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.
library(shiny)
ui <- pageWithSidebar(
headerPanel("My First Shiny App"),
sidebarPanel(
selectInput("TheFile", "Select dataset",
choices = c("DATASET1.csv", "DATASET2.csv"))
),
mainPanel(
tableOutput("Table1"),
tableOutput("Table2"),
tableOutput("Table3")
)
)
server <- function(input, output, session){
OtherData <- reactive({
OutList <- vector(mode = "list", length = 3)
if(input$TheFile == "DATASET1.csv") {
OutList[[1]] <- read.csv("A.csv")
OutList[[2]] <- read.csv("B.csv")
OutList[[3]] <- read.csv("C.csv")
} else {
OutList[[1]] <- read.csv("D.csv")
OutList[[2]] <- read.csv("E.csv")
OutList[[3]] <- read.csv("F.csv")
}
OutList
})
output$Table1 <-renderTable({
OtherData()[[1]]
})
output$Table2 <-renderTable({
OtherData()[[2]]
})
output$Table3 <-renderTable({
OtherData()[[3]]
})
}
# Run the application
shinyApp(ui = ui, server = server)
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 () {
} else if {
} else if {
} else {
}
to handle them all.