Reputation: 485
My ui.R file has a selectInput like this:
selectInput("cluster", "Cluster:",
c("Total" = "Total","East"="East",
"South"="South", )
where "Total" or "South" are supposed to be a vector of colnames list.
Like
East is : East<-c("Strasbourg","Grenoble","Nice")
And
South is : South<-("Nice","Montpellier","Marseille")
like in server.r
file :
i would like to do something like that :
resultscluster<-reactive({
mydataframe[,(names(mydataframe) %in% input$cluster)]
})
When I run the App the ui.R does not know what "cluster".
thanks
Thanks
Upvotes: 0
Views: 1428
Reputation: 19970
In your case, I would probably just use a switch
statement. I also took the liberty of adding a validate
statement requiring an option to be selected.
library(shiny)
East <- c("Strasbourg","Grenoble","Nice")
South <- c("Nice","Montpellier","Marseille")
Total <- c("Strasbourg","Grenoble","Nice",
"Montpellier","Marseille", "coolPlace1", "coolplace2")
# some play data
mydataframe <- as.data.frame(replicate(7, rnorm(10)))
colnames(mydataframe) <- Total
runApp(
list(
ui = pageWithSidebar(
div(),
sidebarPanel(
selectInput("cluster","Cluster:",
c("East","South","Total"))),
mainPanel(
tableOutput("table"))),
server = function(input, output){
resultscluster<-reactive({
validate(
need(!is.null(input$cluster),
"Please select a clutser")
)
switch(input$cluster,
East = mydataframe[,(names(mydataframe) %in% c("Strasbourg","Grenoble","Nice"))],
South = mydataframe[,(names(mydataframe) %in% c("Nice","Montpellier","Marseille"))],
Total = mydataframe[,(names(mydataframe) %in% c("Strasbourg","Grenoble","Nice",
"Montpellier","Marseille", "coolPlace1", "coolplace2"))],
)
})
output$table <- renderTable(resultscluster())
}
))
Upvotes: 3