我的工作是一个闪闪发亮的项目,非常纠结于4.7,它给我们带来了巨大的价值。作为一个免费的字体用户,我不认为我们有任何优势升级到5.3.1。许多免费图标已经变得更丑/更粗糙,一个人将不得不支付专业版本,以获得类似4.7图标样式。
包含9个单元格的4.7中的示例表
在5.3中,表中有4个单元格和较胖的线条。旧的9单元格格式仅供专业用户使用。
从我自己简单的角度来看,这支火爆的团队似乎想大力推动他们的免费用户走向专业。
有什么简单的方法可以同时拥有闪亮的1.2和火锅4.7.1?
编辑链接由猪排似乎非常相关,我将尝试和更新.
发布于 2019-02-05 23:34:38
……这个特定的解决方案可以复制为suggested by Pork Chop旧版本的字体--在安装的闪亮库中非常棒。此外,我还更新了图标()-function,这样就有可能有能够共存的字体版本,并确保正确的链接。在这个解决方案中,在globalEnv中放置了一个新的图标()函数,因此位于search()-path的顶部。这节省了我的代码库遗留问题,而不改变任何其他内容。
然而,为了制作一个新的闪亮应用程序,我会命名图标函数icon_legacy(),以避免依赖search()-path或在支持R包中实现闪亮的应用程序。
##install new shiny version
install.packages("shiny") #install newest shiny
library(shiny)
library(htmltools)
#source in this function to globalEnv
#' Legacy means good old iconic times
#'
#' @param local_path_fa_4.7.1
#' @param shiny_path
#'
#' @return
#' @export
#' @import shiny htmltools
#' @details #this installs legacy font-awesome and return a function similar to icon
#'
#' @examples
#'
#' install.packages("shiny") #install newest shiny
#' library(shiny)
#' library(htmltools)
#' my_fa_path = "./misc/global_source/fa_shiny_4.7.1/font-awesome"
#' icon_legacy = activate_icon_legacy(my_fa_path) #tadaaa use icon_legacy now
#' #btw css pseudo-elements seem to work out-of-the-box also
#'
#' icon = icon_legacy #you may also feel like placing icon in global env to override shiny::icon
activate_icon_legacy = function(
local_path_fa_4.7.1,
shiny_path = system.file(package="shiny")
) {
#find out what version of shiny is installed
uses_fontawesome5 = packageVersion("shiny")>=1.2 #because implemented since 1.2
shiny_resource_path = paste0(shiny_path,"/www/shared")
misses_fontawesome4 = !"font-awesome" %in% list.files(shiny_resource_path) #because new fa dir is called 'fontawesome'
#if legacy dir is missing from library copy into installed library
if(uses_fontawesome5 && misses_fontawesome4) {
file.copy(
from = local_path_fa_4.7.1,
to = shiny_resource_path,
recursive = TRUE,copy.mode = FALSE
)
}
#import minor dependency from shiny library into closure
font_awesome_brands = shiny:::font_awesome_brands
tags = htmltools::tags
#source this modified icon() function from library/shiny/R/bootstrap.R
#notice the legacy feature if true will use old fa 4.7.1 else new
icon_legacy <- function(name, class = NULL, lib = "font-awesome",legacy=TRUE) {
prefixes <- list(
"font-awesome" = "fa",
"glyphicon" = "glyphicon"
)
prefix <- prefixes[[lib]]
# determine stylesheet
if (is.null(prefix)) {
stop("Unknown font library '", lib, "' specified. Must be one of ",
paste0('"', names(prefixes), '"', collapse = ", "))
}
# build the icon class (allow name to be null so that other functions
# e.g. buildTabset can pass an explicit class value)
iconClass <- ""
if (!is.null(name)) {
prefix_class <- prefix
if (prefix_class == "fa" && name %in% font_awesome_brands) {
prefix_class <- "fab"
}
iconClass <- paste0(prefix_class, " ", prefix, "-", name)
}
if (!is.null(class))
iconClass <- paste(iconClass, class)
iconTag <- tags$i(class = iconClass)
# font-awesome needs an additional dependency (glyphicon is in bootstrap)
if (lib == "font-awesome") {
if(legacy) {
htmlDependencies(iconTag) <- htmlDependency(
"fontwesome","4.7.1", "www/shared/font-awesome", package = "shiny",
stylesheet = c("css/font-awesome.css","font-awesome.min.css"))
} else {
htmlDependencies(iconTag) <- htmlDependency(
"font-awesome", "5.3.1", "www/shared/fontawesome", package = "shiny",
stylesheet = c("css/all.min.css","css/v4-shims.min.css")
)
}
}
htmltools::browsable(iconTag)
}
return(icon_legacy)
}
#download extract fontawesome 4.7.1 and write path here
my_fa_path = "./misc/global_source/fa_shiny_4.7.1/font-awesome"
icon_legacy = activate_icon_legacy(my_fa_path) #tadaaa use icon_legacy now
#btwcss pseudos seem to work out-of-the-box also
#one may also feel like placing icon_legacy() as icon() in globalEnv to override shiny::icon
#if youre too lazy change all your original code. This will work any code in ui.R and server.R
#however packages with explicit namespaces are likely not overridden by this.
icon = icon_legacy
#now shiny code will behave like this
icon("table",legacy=TRUE) # old style 9 cell table
icon("table",legacy=FALSE) # new fat 4 cell table
#...one may feel like opting for more explicit and strict namespace solution wrapped in some package.
#but that would be a lot more boiler plate code not relevant for this answer
#this solution also fixed my fontawesome CSS pseudo-elements issues
https://stackoverflow.com/questions/54464295
复制相似问题