【问题标题】:How to enforce choices grouping in selectizeInput?如何在 selectizeInput 中强制选择分组?
【发布时间】:2020-01-02 17:19:31
【问题描述】:

我想在 selectizeInput 中进行分组选择。这可以通过提供一个命名列表作为参数“选择”来完成。 但是,如果组仅包含 1 个元素,则选项的“分组显示”不起作用。 我认为它会干扰为单个参数提供命名向量的选项。我怎样才能实现它,选项总是分组,即使组中恰好只有 1 个元素?

library(shiny)

shinyApp(
  ui = fluidPage(uiOutput("type")),

  server = function(input, output, session) {
    output$type <- renderUI({
      selectizeInput(inputId = "color",
                     label = "Color",
                     choices = list(one = c(3,5,2,5,6),
                                    two = c("no", "yes", "no"),
                                    three = "only_option"),
                     multiple = T)
    })
  }
)

在上述情况下,元素“only_option”被错误地分配给组“two”。

【问题讨论】:

    标签: r shiny selectize.js


    【解决方案1】:

    您必须以列表的形式提供单个选项:

    library(shiny)
    
    shinyApp(
      ui = fluidPage(uiOutput("type")),
      server = function(input, output, session) {
        output$type <- renderUI({
          selectizeInput(
            inputId = "color",
            label = "Color",
            choices = list(
              one = list(3, 5, 2, 5, 6),
              two = list("no", "yes", "no"),
              three = list("only_option")
            ),
            multiple = TRUE
          )
        })
      }
    )
    

    【讨论】:

      猜你喜欢
      • 2019-05-20
      • 1970-01-01
      • 2021-01-08
      • 2019-07-31
      • 1970-01-01
      • 2021-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多