【发布时间】:2020-07-02 23:41:02
【问题描述】:
我正在开发一个闪亮的应用程序,其中包含使用 renderUI 创建的动态 selectInput。
这是server.R中的代码:
output$list_station<- renderUI({
choix_ce <- input$choice_of_ce
postes <- map_consos_enedis %>%
filter(Region == choix_ce) %>%
select(station)
selectInput(inputId = "choice_of_station",
label = "Choix du poste",
choices = as.list(postes),
selected = postes[1],
multiple = FALSE)
})
它几乎可以正常工作...仅当 postes 返回 2 个或更多元素时。如果 postes 返回 1 个元素,下拉列表只包含 station 这是 postes 的变量名,我不明白为什么。
【问题讨论】:
-
你能提供一个 dput(postes) 的例子来帮助理解发生了什么吗?
-
当然!这里 dput(postes) 如果 postes 包含 1 个元素:structure(list(station = "AUCUN"), row.names = c(NA, -1L), class= c("tbl_df", " tbl”,“data.frame”))。并带有 2 个或更多元素(所有元素均未显示):结构(列表(站 = c(“A.DUCP3”,“A.OTHP3”,“ABBENP3”,“ABBENP3”,[........ ],“VOUJEP3”,“VOUJEP3”,“WADONP3”,“WALDIP3”,“WALDIP3”)),row.names = c(NA,-603L),class= c(“tbl_df”,“tbl”,“数据.frame"))