Hi i am trying to figure out how to use the user input i generate to call an existing table in R shiny. Each user input options is the name of a table, i want to use this in
You could use get() to obtain the data.frame. Also, note that input is not a good name for a reactive variable, since it is already defined, therefore I renamed in to inputx. In this case, you could even do without the reactive and simply use output$table<-renderTable({get(input$location)})
Hope this helps!
Dublin=Head(mtcars,5)
Cork=head(mtcars,10)
Galway=head(mtcars,15)
Belfast=head(mtcars,2)
ui=fluidPage(
selectInput(inputId="location",label="Please Choose location",
choices=c("Dublin"="Dublin","Cork"="Cork","Galway"="Galway","Belfast"="Belfast")),
tableOutput("table") )
server=function(input, output){
inputx=reactive({get(input$location)})
output$table<-renderTable(inputx())
}
shinyApp(ui,server)
The cleanest solution would probably be to store your dataframes in a list, and subset from that list as follows:
Dublin=Head(mtcars,5)
Cork=head(mtcars,10)
Galway=head(mtcars,15)
Belfast=head(mtcars,2)
mylist = list(Dublin=Dublin,Cork=Cork,Galway=Galway,Belfast=Belfast)
ui=fluidPage(
selectInput(inputId="location",label="Please Choose location",
choices=c("Dublin"="Dublin","Cork"="Cork","Galway"="Galway","Belfast"="Belfast")),
tableOutput("table") )
server=function(input, output){
output$table<-renderTable(mylist[input$location])
}
shinyApp(ui,server)