我想用数据库查询的结果填充 R shiny 应用程序中的下拉列表。
#I have a global.r file where i put this code:
getData<- function()
{
....this function returns a single column of names. I tested that it does work.
}
#Now in my ui.r file I try to use the function to populate a dropdown list like:
source('global.r')
shinyUI(pageWithSidebar(
selectInput("names", "Select Data",getData(),selected="Name 1" multiple = FALSE)
),
当我运行这个时,下拉列表中填充了查询的标题,而不是查询中返回的整个列表。
任何想法。
谢谢!
最佳答案
如果您希望下拉菜单具有反应性,请使用 uiOutput("names") 而不是 ui.R 中的 selectInput。然后在你的 server.R 中你想要一个像这样的函数:
output$names<-renderUI({
selectInput("names", "Select Data", choices=getData(), selected=names[1])
})
http://shiny.rstudio.com/reference/shiny/latest/renderUI.html http://shiny.rstudio.com/reference/shiny/latest/htmlOutput.html
关于r - 你如何使用 R Shiny 从数据库中填充下拉列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22463079/