I have a question in regards to Shiny. I have four data sets and depending on the user's input, I want to use one of the four data sets for the computations. I tried using an if-statement, but it doesn't work. I also tried using a reactive expression, but could not make that work. Is it technically possible what I want to do? And if so, how?
ui <- fluidPage(
theme = shinytheme("cerulean"),
titlePanel("Some Data"),
sidebarLayout(
sidebarPanel(
checkboxGroupInput("checkGroup", label = h3("Choose your tea brand:"),
choices = list("Solar" = 1,
"Green" = 2,
"Cat" = 3,
"Conservation" = 4)),
selectInput("tea", "Choose your tea:", c("Green Tea", "Black Tea", "Blue Tea")
),
mainPanel(
tabsetPanel(
tabPanel("Titel",
h4("Subtitel"),
verbatimTextOutput("demographicsTable"),
h4("Subtitel"),
tableOutput("nbhsizeTable"),
))))
server <- function(input, output) {
if(input$checkGroup == "Solar"){
Data <- read.csv("SolarData.csv")
} else if(input$checkGroup == "Green"){
Data <- read.csv("GreenData.csv")
} else if(input$checkGroup == "Conservation"){
Data <- read.csv("ConservationData.csv")
} else if(input$checkGroup == "Cat"){
Data <- read.csv("CatData.csv")
}
output$demographicsTable <- renderPrint({
dat <- Data %>% filter(grepl(input$tea, cookies))
### age
age <- summary(dat$age)
### gender
gender <- table(dat$gender)
dat <- list(Age = c(age[1], age[4], age[6]),
Gender = gender)
dat
})
output$nbhsizeTable <- renderTable({
dat <- Data %>% filter(grepl(input$tea, cookies))
table(dat$size_of_teacup)
})