I have three tables (math, science, and literature results). I would like to have a "dynamic" table that updates some columns when clicking a checkboxGroupInput option. To do that, I'm using the bind_rows function, but I'm not being able to update the table the way I want.
The final output needs to be something like the gif below:
(1) When I click "math" it shows the math results
(2) when I click "literature" (sorry for the typo), it shows the literature results
etc..
I added
if (input$overall_boxes == "sci") { table_science } else { FALSE } #when I click "sci" is shows the science results (and keep the math if math is selected)
if (input$overall_boxes == "lit") { table_litterature } else { FALSE }
on purpose to demonstrate what is the goal.
If you have another strategy to run that, feel comfortable changing the following code
library(shiny)
library(tidyverse)
table_math <- data.frame(age = c(5,10), test = "math", result = rnorm(100,10,2))
table_science <- data.frame(age = c(10,15), test = "science", result = rnorm(100,8,2))
table_litterature <- data.frame(age = c(5,15), test = "litterature", result = rnorm(100,5,2))
# Define UI for application that draws a histogram
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
checkboxGroupInput("overall_boxes", label = h3("This is a Checkbox group"),
choices = list("Math" = "math", "Sciences" = "sci", "Litterature" = "lit"),
selected = "math")
),
# Show a plot of the generated distribution
mainPanel(
dataTableOutput("main_results")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
#backend
merge_results <- reactive({
bind_rows(
if (input$overall_boxes == "math") { table_math } else { FALSE } #when I click "math" is shows the math results
)
})
#real output
output$main_results <- renderDataTable(
merge_results()
)
}
# Run the application
shinyApp(ui = ui, server = server)