r - 你如何使用 R Shiny 从数据库中填充下拉列表?

标签 r shiny

我想用数据库查询的结果填充 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/

相关文章:

R,插入符 : what does returnResamp mean in trainControl?

即使可以从终端运行相同的命令,R system() 也无法分配内存

r - 数据框的标准偏差不起作用

r - 如何在 ggplot2 中绘制并排条形图?

R Shiny 拉丝点表空白 NA 行

r - 如何通过 Shiny 的应用程序将更新的表格或数据框保存在现有的 csv 文件中?

删除 ggplot2 中的绘图边距

r - 当用户输入 numericInput 时更改数据帧值

html - 设置灰度背景图像 - Shiny R

r - 如何将shapefile上传到Shiny App