Shiny: Feature Request: Update font-awesome version

Created on 3 Mar 2018  Â·  5Comments  Â·  Source: rstudio/shiny

https://github.com/rstudio/shiny/blob/174a1fe83437008bca69e48fe346470e5c09ecb9/R/bootstrap.R#L1547

I've noticed theres been huge changes the font-awesome icons in the last few versions they have released, the documentation for icons() is now is incorrect as most of the icons listed through their explorer will fail to load when using in shiny app.

Please update the font-awesome font files or the new svg implementation

Most helpful comment

We've decided to upgrade to 5.3.1 and include the fontawesome v4 compatibility shim. This should ensure that everybody can use the new icons without existing apps breaking (though some of the fancy new functionality in fontawesome 5 will not be available--hopefully you will be able to use that through the rstudio/fontawesome or ropenscilabs/icon package).

All 5 comments

Which link are you following to the list of Font Awesome icons? If one heads over to the Font Awesome 4.7 website, see https://fontawesome.com/v4.7.0/, the icons listed ought to all work with icon(). The updates in Font Awesome 5 are not trivial. For now the best solution may be to make sure Shiny's documentation points to the Font Awesome 4.7 website.

Just adding a +1 for this request.
It gets confusing with the shiny help pages pointing to a page of icons where 90% of them are unusable with no clear indication (to new users) as to why some wouldn't/wouldn't work.

I just committed some changes into a fork at https://github.com/JesseVent/shiny/commit/9ce6f87094ba5f6d4ca00455296a02d83454172d which appear to work, build passes all tests and CRAN checks. So could be something to look into - Unfortunately I couldn't think of a way to provide fallback support for 4.7.0 other than using a mapping document in a csv file.

Seems to work pretty well in the scenarios I tested, definitely renders in-app. Hope it helps.

icon <- function(name, class = NULL, lib = "font-awesome", style="fas") {
  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 = ", "))
  }

  # Add fallback support for 4.7.0 by checking for legacy icons names and replacing with 5.2.0 names
  if ( prefix == "fa" && !is.null(name)) {
    mapfile <- system.file("www","shared","font-awesome", "fa-mapping.csv", package = "shiny")
    fa_lookup  <- read.csv(mapfile, stringsAsFactors = FALSE)
    match      <- match(name, fa_lookup$v4_name)
    prefix_tag <- NA
    if (!is.na(match)) {
      match      <- as.numeric(match)
      name       <- fa_lookup$v5_name[match]
      prefix_tag <- fa_lookup$prefix[match]
    }
    if (is.na(prefix_tag)) prefix_tag <- style
  }

  # 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)) {
    # support for glyphicon
    if(prefix != "fa") iconClass <- paste0(prefix, " ", prefix, "-", name)
    # new font-awesome format
    if(prefix == "fa") iconClass <- paste0(prefix_tag, " ", 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") {
    htmltools::htmlDependency("font-awesome", "5.2.0", c(href="shared/font-awesome"), script = "js/all.js")
  }
  iconTag
}
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking Rd contents ... OK
* checking for unstated dependencies in examples ... OK
* checking examples ... OK
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ...
* Running ‘test-all.R’ OK
* DONE
Status: 1 NOTE
checking installed package size ... NOTE

R CMD check results
0 errors | 0 warnings | 1 note 

R CMD check succeeded

We've decided to upgrade to 5.3.1 and include the fontawesome v4 compatibility shim. This should ensure that everybody can use the new icons without existing apps breaking (though some of the fancy new functionality in fontawesome 5 will not be available--hopefully you will be able to use that through the rstudio/fontawesome or ropenscilabs/icon package).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FrissAnalytics picture FrissAnalytics  Â·  5Comments

hudon picture hudon  Â·  4Comments

wch picture wch  Â·  3Comments

EmileArseneault picture EmileArseneault  Â·  5Comments

Stophface picture Stophface  Â·  3Comments