如何在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
相关产品推荐
相关产品推荐

