闪亮的降级字体很棒5到4 [英] shiny downgrade fontawesome 5 to 4

查看:64
本文介绍了闪亮的降级字体很棒5到4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事一个与fontawesome 4.7纠缠在一起的闪亮项目,它为我们带来了巨大的价值.作为fontawesome的免费用户,我认为升级到5.3.1没有任何优势.许多免费图标变得更加丑陋,而且必须付费购买专业版才能获得类似于4.7的图标样式.

I work on a shiny project quite entangled with fontawesome 4.7, and it has brought us great value. As a free user of fontawesome, I don't see we have any advantage of upgrading to 5.3.1. Many of the free icons have become uglier/cruder, and one would have to pay for the pro version to get the icon styles similar to 4.7.

示例表可在4.7中使用9个单元格

Example table available in 4.7 with 9 cells

只有4个单元格,而有些胖的线条.旧的9单元格格式仅适用于专业用户

in 5.3 table is onle free as 4 cells and rather chubby lines. The old 9 cell format is only available for pro users

从我自己的简单角度来看,丰盛的团队似乎打算大力推动其免费用户成为专业人士.

From my own simple perspective, it seems the fontawesome team intends to strongly nudge their free users to go pro.

  • Rstudio闪亮1.1链接到fontawesome 4.7.1
  • Rstudio Shiny 1.2链接到Fontawesome 5.3.1

有没有简单的方法可以同时拥有闪亮的1.2和惊人的4.7.1?

编辑 猪排链接似乎非常相关,我将尝试并更新...

EDIT Link by pork chop seems very relevant, I will try it out and update...

推荐答案

  • 下载fontawesome 4.7.1&解压缩
  • 将下面的代码插入global.R
  • 将路径更新为未压缩的字体
  • ....然后闪亮就可以同时完成4.7.1和+5.此特定解决方案复制为由猪排建议已安装的闪亮库中font-awesome的版本.另外,我还更新了icon()函数,以便可以将一些字体版本共存并确保正确链接.在此解决方案中,新的icon()函数放置在globalEnv中,因此位于search()-path的顶部.这节省了我的代码库遗留问题,而无需进行其他任何更改.

    .... and then shiny can do both fontawesome 4.7.1 and +5. This specific solution copies as suggested by Pork Chop old version of font-awesome in installed shiny library. Also I updated the icon()-function so it is possible to have fontawesome versions to coexist and to ensure correct linking. In this solution a new icon() function is placed in globalEnv hence in top of search()-path. That saved my code base legacy issues without changing anything else.

    但是,对于制作新的闪亮应用程序,我将命名为icon-function icon_legacy()以避免依赖search()-path或在用于闪亮应用程序的支持R程序包中实现.

    However for making a new shiny-application, I would name icon-function icon_legacy() to avoid relying on search()-path or implement in a support R-package for shiny-application.

    ##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
    

    这篇关于闪亮的降级字体很棒5到4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆