首页 > 解决方案 > 如何在 R Shiny 的选择输入中修改多个选定值的显示

问题描述

我构建了一个具有多选输入的 Shinyapp。一切正常,但是当我选择多个值时,

这是我说的丑陋的盒子

有没有办法格式化所选值的显示?也许只是在带有选项的下拉列表中打勾或类似的东西?

标签: rshiny

解决方案


您可以使用此 css 更改选择框中项目的颜色

在此处输入图像描述

.selectize-control.multi .selectize-input > div {
        background: #d8544c;
        color: #fdfdfd;
}

示例应用程序代码:

library(shiny)

ui <- fluidPage(
    tags$head(
        tags$style(HTML("
        
      .selectize-control.multi .selectize-input > div {
        background: #d8544c;
        color: #fdfdfd;
}

    "))
    ),
    sidebarLayout(
        sidebarPanel(
            selectInput("select1",
                        "Choices:",
                        choices = names(mtcars), multiple = TRUE)
        ),
    mainPanel(
        verbatimTextOutput("out")
        )
    )
)

server <- function(input, output) {
    output$out <- renderPrint({
      input$select1
    })
}

shinyApp(ui = ui, server = server)

推荐阅读