How to hide
/show
several elements at once with shinyjs? In the following example my goal is to hide/show both tables with just two lines of code instead of four. Why do I want to do this? In reality, I am dealing with several tables and several events such that showing/hiding them all at once would keep the code a lot cleaner.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
actionButton("hide","Hide!"),
actionButton("show","Show!"),
tableOutput("table1"),
tableOutput("table2"))
server <- function(input, output, session) {
output$table1 <- renderTable({head(iris)})
output$table2 <- renderTable({head(iris)})
observeEvent(input$hide, {hide("table1")})
observeEvent(input$show, {show("table1")})
observeEvent(input$hide, {hide("table2")})
observeEvent(input$show, {show("table2")})}
shinyApp(ui, server)