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

如何在Shiny应用中指定文本右侧插入绿色info信息图标

实现方法

直接调用Shiny内置的icon()函数即可调用fontawesome的info图标,通过style参数设置为绿色后,和目标文本放在同一个标签容器内就能实现需求,额外加了5px左间距避免图标和文本挨得太近,修改逻辑如下:

  • 替换原UI中侧边栏面板的h4("Select the best the number of bins")代码段即可:
h4(tagList(
  "Select the best number of bins",
  icon("info-circle", style = "color: green; margin-left: 5px;")
))

完整可运行代码

library(shiny)
library(shinythemes)

ui <- fluidPage(
  titlePanel("Old Faithful Geyser Data"),
  sidebarLayout(
    sidebarPanel(
      # 带绿色info图标的标题
      h4(tagList(
        "Select the best number of bins",
        icon("info-circle", style = "color: green; margin-left: 5px;")
      )),
      br(),
      br(),
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),
    mainPanel(
      plotOutput("distPlot")
    )
  )
)

server <- function(input, output) {
  output$distPlot <- renderPlot({
    x    <- faithful[, 2]
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })
}

shinyApp(ui = ui, server = server)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.05 17:48:03