You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在ShinyWidgets中正常使用Fluent UI图标

Fluent UI图标加载异常解决方案

核心问题原因

  1. Fluent UI样式表引入时type属性拼写错误:你代码中写的是text/cstt,正确值为text/css,直接导致样式文件无法被浏览器识别加载。
  2. checkboxGroupButtons默认会转义HTML内容,未关闭转义的情况下,你写的<i>标签会被当做纯文本渲染,无法生成图标。

修正后的完整代码

library(shiny)
library(shiny.fluent)
library(shinyWidgets)

ui <- fluidPage(
  tags$link(rel = "stylesheet", type = "text/css", href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"),
  # 修正type属性拼写错误
  tags$link(rel = "stylesheet", type = "text/css", href = "https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/11.0.0/css/fabric.min.css"),
  
  checkboxGroupButtons(
    inputId = "check",
    label = "Choose a graph :", 
    # 拆分choiceNames和choiceValues,搭配escape=FALSE关闭HTML转义
    choiceNames = list(
      HTML("<i class='fa fa-bar-chart'></i>"),
      HTML("<i class='fa fa-signal'></i>"),
      HTML("<i class='fa fa-terminal'></i>"),
      HTML("<i class='glyphicon glyphicon-tree-deciduous'></i>"),
      HTML('<i class="ms-Icon ms-Icon--Color" aria-hidden="true"></i>')
    ),
    choiceValues = c("bar", "signal", "terminal", "tree", "Color"),
    justified = FALSE,
    choicesOpt = list(escape = FALSE)
  ), 
  verbatimTextOutput("OUT"), 
  span("FontIcon expression in shiny.fluent"), FontIcon(iconName = "Color"),br(),
  span("glyphicon i tag"), tags$i(class="glyphicon glyphicon-tree-deciduous"),br(),
  span("Fluent UI i tag :"), tags$i(class="ms-Icon ms-Icon--Color"),br(),
  span("Fontawesome i tag:"), tags$i(class="fa fa-bar-chart")
)

server <-function(input, output, session)
{
  output$OUT <- renderText({
    print(input$check)
  })
}

shinyApp(ui = ui, server = server)

验证效果

修正后可正常实现以下效果:

  • 直接通过tags$i()调用的Fluent UI图标正常显示
  • checkboxGroupButtons选项中的Fluent UI图标正常渲染
  • 原有Fontawesome、Glyphicon图标不受影响,功能正常

内容的提问来源于stack exchange,提问作者BJK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 13:24:02