R is brilliant; how to use multiple inputs from selectInput to go to the "select" option in dplyr?

I have an application in which I want to enter user input in the "ui" file and use this information to update the data frame in the "server" file. The following is a simplified version of the code:

Dataframe <- readRDS(Dataframe.rds) Table <- readRDS(Table.rds) ui <- fluidPage( selectInput("Location","Location", unique(as.character(Table$Locations)), multiple = TRUE) ) server <- function(input,output) { Dataframe2 <- Dataframe %>% select(get(input$Location)) } 

The above code works if I do not use the "multiple = TRUE" parameter for selectInput, which means that the Dataframe2 object selects only the column corresponding to one input selected by the user. However, I do not know how I can do the same for multiple inputs, when the selection can vary from one element passed from selectInput to 10 elements in total.

+6
source share
1 answer

If I understood your question correctly, this is a multiple-choice example using the mtcars data frame:

ui.R

  library(shiny) data(mtcars) shinyUI(fluidPage( titlePanel("MTCARS"), selectInput("Columns","Columns", names(mtcars), multiple = TRUE), verbatimTextOutput("dfStr") )) 

server.R

  library(shiny) library(dplyr) data(mtcars) shinyServer(function(input, output) { Dataframe2 <- reactive({ mtcars[,input$Columns] }) output$dfStr <- renderPrint({ str(Dataframe2()) }) }) 
+6
source

All Articles