gpt4 book ai didi

r - 只有一个项目的分组选择输入

转载 作者:行者123 更新时间:2023-12-04 11:25:40 26 4
gpt4 key购买 nike

我想按照此处的说明对我的 selectInput 数据进行分组:https://shiny.rstudio.com/gallery/option-groups-for-selectize-input.html .除了组中只有一个项目的情况外,一切正常。

这是一个示例(第一个正确的 selectInput 和奇怪的第二个):

library(shiny)

ui <- fluidPage(
selectInput("country", "Select country", list(
"Europe" = c("Germany", "Spain"),
"North America" = c("Canada", "United States" = "USA")
)),

selectInput("country", "Select country", list(
"Europe" = c("Germany", "Spain"),
"North America" = c("Canada")
))
)

server <- function(input, output, session) {
}

shinyApp(ui = ui, server = server)

效果:

enter image description here

你知道怎么处理吗?

最佳答案

我不知道为什么会这样,但这对我来说是这样的

library(shiny)

ui <- fluidPage(
selectInput("country", "Select country", list(
"Europe" = c("Germany", "Spain"),
"North America" = c("Canada", "United States" = "USA")
)),

selectInput("country", "Select country", list(
"Europe" = c("Germany", "Spain"),
"North America" = c("Canada", "")
))
)

server <- function(input, output, session) {
}

shinyApp(ui = ui, server = server)

代码的唯一区别是我在此处添加了"" "North America"= c("Canada", "")。这给了我

Output

关于r - 只有一个项目的分组选择输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57248427/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com