I have the following CSV files in my working directory:
DATASET1.csv
DATASET2.csv
A.csv
B.csv
C.csv
D.csv
E.csv
F.csv
I want a user to be able to choose in a dropdown menu to load DATASET1, or DATASET2. This works for me into what I will call myCSV. This has been working for me :
This is great but I'm not having much luck implementing it (trying to insert it into my code - I posed it as another thread but didn't get any response).
Is there any way that instead of 'if not DATASET1, load D,E,F instead that it could be more like "If DATASET2, load DEF) ? I'm wondering because I eventually would like to insert 10+ choices and not only 2.
This toy example works for me. It does not even try to load the files DATASET1.csv or DATASET2.csv but it does jump between loading the files A.csv, B.csv, etc.
I do not understand what you are referring to with "Is there any way that instead of 'if not DATASET1, load D,E,F...". My first code loaded A, B and C if the input was selected as DATASET1.csv. If you have several such options you can use a set of
If your file names are as regular in your actual use case as they are in your example (or can be made regular), I think you can select the appropriate files as follows: In the code below, we get the number at the end of the DATASET name and feed that to a function that maps that number to the three unique letter files that go with it. The we read those three letter files:
library(tidyverse)
# Function to identify and read the desired LETTER files for a given DATASET
rf = function(dataset.num) {
n = (dataset.num - 1) * 3 + 1
files = paste0(LETTERS[n:(n+2)], ".csv")
map(files, read_csv)
}
# Get number of DATASET
num = as.numeric(stringr::str_extract(input$TheFile, "[0-9]"))
# Read the appropriate letter files
OutList = rf(num)
Since there are only 26 letters, this particular mapping would work for 8 different DATASET files. But you could call your three target files for DATASET11a.csv, 1b.csv, 1c.csv, and likewise for DATASET2, etc., and the code above could be adjusted accordingly.