【问题标题】:How to modify the display of multiple selected values in select input in R Shiny如何在 R Shiny 的选择输入中修改多个选定值的显示
【发布时间】:2020-10-26 17:25:31
【问题描述】:

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

This is the ugly box I'm talking about

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

【问题讨论】:

  • 这样的格式化细节需要定义一个自定义的 CSS 文件,这是一个完整的冒险,只是为了移除盒子。从selectInput 切换到checkboxGroupInput 会解决您的问题吗?
  • 或者看看pickerInput来自shinyWidgets

标签: r shiny


【解决方案1】:

您可以使用此 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)

【讨论】:

  • 有没有办法改变框的显示?不仅是颜色,还有显示所选选项的方式?
猜你喜欢
  • 2019-08-21
  • 1970-01-01
  • 2016-11-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多