所以,我正在尝试从命名列表中进行选择,该列表在跟随selectInput参考页面时效果很好:
## Only run examples in interactive R sessions
if (interactive()) {
# basic example
shinyApp(
ui = fluidPage(
selectInput("variable", "Variable:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear")),
tableOutput("data")
),
server = function(input, output) {
output$data <- renderTable({
mtcars[, c("mpg", input$variable), drop = FALSE]
}, rownames = TRUE)
}
)
# demoing optgroup support in the `choices` arg
shinyApp(
ui = fluidPage(
selectInput("state", "Choose a state:",
list(`East Coast` = c("NY", "NJ", "CT"),
`West Coast` = c("WA", "OR", "CA"),
`Midwest` = c("MN", "WI", "IA"))
),
textOutput("result")
),
server = function(input, output) {
output$result <- renderText({
paste("You chose", input$state)
})
}
)
}
但是,如果我使用包含带有单个元素的命名向量的列表,则会以某种方式更改选择器组织,仅显示列表名称,但不显示它们包含的单个元素向量。
## Only run examples in interactive R sessions
if (interactive()) {
# basic example
shinyApp(
ui = fluidPage(
selectInput("variable", "Variable:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear")),
tableOutput("data")
),
server = function(input, output) {
output$data <- renderTable({
mtcars[, c("mpg", input$variable), drop = FALSE]
}, rownames = TRUE)
}
)
# demoing optgroup support in the `choices` arg
shinyApp(
ui = fluidPage(
selectInput("state", "Choose a state:",
list(`East Coast` = c("NY"),
`West Coast` = c("WA", "OR", "CA"),
'North Coast' = c("canada"),
`Midwest` = c("MN", "WI", "IA"),
'south coast' = c("Argentina")
)
),
textOutput("result")
),
server = function(input, output) {
output$result <- renderText({
paste("You chose", input$state)
})
}
)
}
任何想法如何绕过这个?
答案 0 :(得分:1)
如果对单个元素列表项使用命名向量,它将呈现组和子组。实时应用here。
shinyApp(
ui = fluidPage(
selectInput("state", "Choose a state:",
list(`East Coast` = c("NY" = "ny"),
`West Coast` = c("WA", "OR", "CA"),
`North Coast` = c("Canada" ="canada"),
`Midwest` = c("MN", "WI", "IA"),
`south coast` = c("Argentina" = "argentina")
)
),
textOutput("result")
),
server = function(input, output) {
output$result <- renderText({
paste("You chose", input$state)
})
}
)