1

I have an RShiny app that builds a number of plots based on input data. Currently I am using a selectInput widget that allows the user to choose a data source (sources are all csv files located in the same directory as the app) - the app then performs a read.csv on the selected source and creates the plots. Currently there are only two files to choose from, but soon there will be at least ten. Here's a sample of the relevant code:

UI:
selectInput("sample", label=h4("Select pre-loaded data to view"),
                        choices=c('sample 1', 'sample 2'), selected='sample 1',
                        multiple=FALSE),
Server:
load_data <- reactive({
        if (input$sample == "sample 1") {
            df <- read.csv('sample1.csv')
            umap_df <- read.csv('sample1_umap.csv')
        } else {
            df <- read.csv('sample2.csv')
            umap_df <- read.csv('sample2_umap.csv')
        }

        selected_data <- list()
        selected_data$df <- df
        selected_data$umap <- umap_df
        return(selected_data)
    })

I now want to update the app so that the user can select multiple data sources at a time to compare their plots. I know the first step is changing selectInput to include multiple=TRUE, but how can I parse multiple input$sample values in my load_data function?

wylie
  • 173
  • 11
  • Hi, can you post a [minimal and reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? It will be easier to help you with that – bretauv Jun 09 '20 at 17:01
  • I'd recommend replacing your if/then/else statement with `lapply(input$sample, function(d){ ##collapse the text to match the file name ## paste the file name to read.csvs ## return a list of two data.frames})`. This will return a list object you can manipulate downstream. – Ryan Morton Jun 09 '20 at 18:18

0 Answers0