我想用数据库查询的结果填充 R 闪亮应用程序中的下拉列表。
#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/renderUI.html
http://shiny.rstudio.com/reference/shiny/latest/htmlOutput.html http://shiny.rstudio.com/reference/shiny/latest/htmlOutput.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)