observeEvent() with multiple inputs

library(shiny)

Page1 <- div(class = 'container', id = "Page1",
    actionButton("B1", "B1"),
    actionButton("B2", "B2")
)
Page2 <- div(class = 'container', id = "Page2",
             actionButton("B3", "B3"))
             
ui <- fluidPage(
  conditionalPanel("output.page_to_show == 'Page1'",
                   Page1),
  conditionalPanel("output.page_to_show == 'Page2'",
                   Page2)
)


server <- function(input, output) {
  page_to_show <- reactiveVal("Page2")
  
  output$page_to_show <- reactive(page_to_show())
  
  outputOptions(output, "page_to_show", suspendWhenHidden = FALSE)
  

  observeEvent(c(input$B1 , input$B2),
               {
                 page_to_show("Page2")
               })
  observeEvent(input$B3,
               {
                 page_to_show("Page1")
               })
}

shinyApp(ui = ui, server = server)
1 Like