我的ui.R文件有一个像这样的selectInput:
selectInput("variable1", "Choose Option:", camps)
Run Code Online (Sandbox Code Playgroud)
其中camps被认为是一个选项矢量.此向量取决于在服务器脚本上运行的sql查询并返回阵营的ID:
server.R
df1 <- getCamps("date")
camps <- unique(df1$idCamps)
Run Code Online (Sandbox Code Playgroud)
当我运行App时,ui.R不知道"阵营"是什么,因为它只在server.R文件中创建.如何将server.R文件中创建的阵营向量传递给ui.R文件,以便它们现在可以在selectInput选择器中进行选择?
MDe*_*MDe 34
您需要在server.R中创建一个输入对象,并将其作为output列表的一部分返回给ui.R :
在server.R中:
df1 <- getCamps("date")
camps <- unique(df1$idCamps)
output$campSelector <- renderUI({
selectInput("variable1", "Choose Option:", as.list(camps))
})
Run Code Online (Sandbox Code Playgroud)
在ui.R:
uiOutput("campSelector")
Run Code Online (Sandbox Code Playgroud)