简体   繁体   English

shinydashboard 一些 Font Awesome 图标不工作

[英]shinydashboard some Font Awesome Icons Not Working

When using shinydashboard I find that some icons seem to work while some don't.使用shinydashboard时,我发现有些图标似乎有效,有些则无效。 In the below example, the battery-full icon doesn't work while the clock-o icon works fine.在下面的示例中,电池充满图标不起作用,而时钟关闭图标可以正常工作。 I'm unable to figure out why this should happen.我无法弄清楚为什么会发生这种情况。

library(shiny)
library(shinydashboard)

header <- dashboardHeader(title="Some Icons Not Working?")

# No sidebar --------------------------------------------------------------

sm <- sidebarMenu(

  sm <- sidebarMenu(
    menuItem(
      text="asdf",
      tabName="asdfasdf",
      icon=icon("battery-full")),
    menuItem(
      text="qwer",
      tabName="qwerqwer",
      icon=icon("clock-o"))
  )
)

sidebar <- dashboardSidebar(sm)

# Compose dashboard body --------------------------------------------------

body <- dashboardBody(

  tabItems(

  )
)

# Setup Shiny app UI components -------------------------------------------

ui <- dashboardPage(header, sidebar, body, skin="black")

# Setup Shiny app back-end components -------------------------------------

server <- function(input, output) {


}

# Render Shiny app --------------------------------------------------------

shinyApp(ui, server)

Ok, I think the new ones in version 4.4 are not updated.好吧,我认为4.4版本中的新内容没有更新。 You can probably request shiny team to update them and they will do it very easily.您可能可以要求shiny团队更新它们,他们会很容易做到。 Alternatively you can do it yourself by downloading them and replacing the previous content...或者,您可以通过下载它们并替换以前的内容来自己完成...

1. Go to the Font Awesome download page and get it 1.前往Font Awesome 下载页面并获取在此处输入图片说明

2. Locate your font awesome folder where you installed shiny package. 2.找到安装了shiny包的字体真棒文件夹。 This should be somewhere like here ~\\Documents\\R\\win-library\\3.1\\shiny\\www\\shared\\font-awesome这应该是这样的地方~\\Documents\\R\\win-library\\3.1\\shiny\\www\\shared\\font-awesome

3. Replace the content of this folder with new contents (you can delete the previous content if you want). 3.用新的内容替换这个文件夹的内容(如果需要,您可以删除以前的内容)。 Below is what I put in there下面是我放在那里的在此处输入图片说明

4. Now your app should work fine with new fonts 4.现在您的应用程序应该可以正常使用新字体在此处输入图片说明

This is an older question, but the issue remains for me in July 2020. I found the solution in the github issues page .这是一个较旧的问题,但问题仍然存在于 2020 年 7 月。我在github 问题页面中找到了解决方案。 The trick is to make sure you are looking at the library of icons in the version of Font Awesome Shiny is calling.诀窍是确保您正在查看 Font Awesome Shiny 正在调用的版本中的图标库。 Currently (again, July 2020) the version is 4.7.目前(再次,2020 年 7 月)版本是 4.7。 All of these icons currently work.所有这些图标目前都有效。

Another option is to call the version of fontawesome you want using the following code within your app's ui function (this solution originally posted here ):另一种选择是在应用程序的 ui 函数中使用以下代码调用您想要的 fontawesome 版本(此解决方案最初发布在此处):

tags$style("@import url(https://use.fontawesome.com/releases/v5.7.2/css/all.css);")

Now that shiny::icon is powered by the fontawesome r package, you can use fontawesome:::fa_tbl to help you find the names that are expected from the function. fontawesome:::fa_version also tells you what fontawesome version is currently in the R package.现在 shiny::icon 由 fontawesome r package 提供支持,您可以使用 fontawesome::fa_tbl 来帮助您找到预期来自 function 的名称。 R package。

对我来说,在 2020 年 10 月,解决方案是在第一个“fa”之后添加一个“s”,就像在fa fa-caret-upfas fa-caret-up因为它是字体真棒图标的新语法。

For those newcomers in 2021, this icon ... does not exist error is due to the Font Awesome changing names to their icons between 4 and 5 (see background here ).对于 2021 年的新人,此图标...不存在错误是由于 Font Awesome 将其图标名称更改为 4 到 5 之间(请参阅此处的背景)。 Below are solutions that do not require tag styles.以下是不需要标签样式的解决方案。

If you are getting this error message,如果您收到此错误消息,

This Font Awesome icon ('{youriconname}') does not exist: 这个 Font Awesome 图标 ('{youriconname}') 不存在:

* if providing a custom html_dependency these name checks can be deactivated with verify_fa = FALSE * 如果提供自定义html_dependency可以使用verify_fa = FALSE停用这些name检查

then, you can either:然后,您可以:

  1. Embrace the change and rename your icon, looking at the library, link to 5.1.5 for example , to find a new name for your match.接受更改并重命名您的图标,查看库,例如链接到 5.1.5,为您的匹配找到一个新名称。 In my case it was changing icon('dashboard') to icon('tachometer-alt').就我而言,它正在将 icon('dashboard') 更改为 icon('tachometer-alt')。 Search with your old name, and look at the free, not grayed out, icons for an alternative.使用您的旧名称进行搜索,然后查看免费的而非灰显的图标以寻找替代方案。

  2. Use this useful workaround by @samssann from shinydashboard issue 373 :使用来自shinydashboard issue 373的@samssann的这个有用的解决方法

    1. add verify_fa = FALSE argument to shiny::icon()verify_fa = FALSE参数添加到verify_fa = FALSE shiny::icon()
    2. use shiny::icon("clock") or fontawesome::fa("clock")使用fontawesome::fa("clock") shiny::icon("clock")fontawesome::fa("clock")

PS You might find the icon still shows on your app despite the error as there is a shim to plug 4 to 5. See @jcheng's answer here from shiny issue #1966. PS 您可能会发现尽管出现错误,但该图标仍然显示在您的应用程序上,因为有一个垫片可以插入 4 到 5。请参阅此处来自闪亮问题 #1966 的@jcheng 的回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM