Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get vector of options from server.R to ui.R for selectInput in Shiny R App

Tags:

r

shiny

My ui.R file has a selectInput like this:

selectInput("variable1", "Choose Option:", camps) 

where camps is supposed to be a vector of options. This vector depends on a sql query that runs on the server script and returns the IDs of the camps:

server.R

df1 <- getCamps("date") camps <- unique(df1$idCamps) 

When I run the App the ui.R does not know what "camps" is because it is only created in the server.R file. How can I pass the vector of camps created in the server.R file to the ui.R file so that they are now the options to choose from in the selectInput selector?

like image 314
Cybernetic Avatar asked Apr 21 '14 16:04

Cybernetic


Video Answer


1 Answers

You need to create an input object in server.R, and return it to ui.R as part of the output list:

In server.R:

df1 <- getCamps("date") camps <- unique(df1$idCamps) output$campSelector <- renderUI({    selectInput("variable1", "Choose Option:", as.list(camps))  }) 

In ui.R:

uiOutput("campSelector") 
like image 92
MDe Avatar answered Oct 08 '22 15:10

MDe