如何在 selectizeInput 中强制选择分组?
How to enforce choices grouping in selectizeInput?
我想在 selectizeInput 中对选项进行分组。这可以通过提供命名列表作为参数 "choices" 来完成。
但是,如果一个组仅包含 1 个元素,则 "grouped display" 选项不起作用。
我认为它干扰了为单个参数提供命名向量的选项。我怎样才能做到,选项总是分组,即使组中恰好只有 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"。
您必须以列表形式提供单个选项:
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
)
})
}
)
我想在 selectizeInput 中对选项进行分组。这可以通过提供命名列表作为参数 "choices" 来完成。 但是,如果一个组仅包含 1 个元素,则 "grouped display" 选项不起作用。 我认为它干扰了为单个参数提供命名向量的选项。我怎样才能做到,选项总是分组,即使组中恰好只有 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"。
您必须以列表形式提供单个选项:
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
)
})
}
)