我的ui.R文件有一个像这样的selectInput:
selectInput("variable1", "Choose Option:", camps)
其中camps
应该是选项的向量。此向量取决于在服务器脚本上运行的sql查询,并返回阵营的ID:
server.R
df1 <- getCamps("date")
camps <- unique(df1$idCamps)
当我运行App时,ui.R不知道“阵营”是什么,因为它只在server.R文件中创建。如何将server.R文件中创建的阵营向量传递给ui.R文件,以便它们现在可以在selectInput选择器中进行选择?
答案 0 :(得分:32)
您需要在server.R中创建一个输入对象,并将其作为output
列表的一部分返回给ui.R:
在server.R中:
df1 <- getCamps("date")
camps <- unique(df1$idCamps)
output$campSelector <- renderUI({
selectInput("variable1", "Choose Option:", as.list(camps))
})
在ui.R:
uiOutput("campSelector")
答案 1 :(得分:0)
更简单的方法:使用barPlot()函数为我工作。
names(dataframe_name[colm])
,
在我的情况下,colm
是colm <- as.numeric(input$parameters)
然后我从ui.r获取parameters
,其中参数是
selectInput("parameters", label = "1. Select the variable from the U.F.O. dataset", choices = c("Shape" = 7, "Country" = 4, "AM/PM" = 3, "State" = 6))