简体   繁体   中英

How to listen for more than one actionbutton within a Shiny observeEvent to reload shiny

Here is the question, I have two dynamically rendered action buttons that are designed to reload the session, but I have trouble listening to them, it is like an OR action, each of them is clicked and then the session reloads. Here is the code:

ui <- shinyUI(bootstrapPage(
  p('cbldwbvkdj'),
  uiOutput('aa')
  )
)

server <- shinyServer(function(input, output, session) {
  output$aa<-renderUI({
    actionButton("test1", "test1")
    actionButton("test2", "test2")
  })
  observeEvent(paste0(input$test1, input$test2), {
    session$reload()
  }, ignoreInit = T)
})

shinyApp(ui, server)

You can add req to the observeEvent :

library(shiny)
ui <- shinyUI(
    bootstrapPage(
        p('cbldwbvkdj'),
        uiOutput('aa')
    )
)

server <- shinyServer(function(input, output, session) {
    
    output$aa <- renderUI({
        tagList(
            actionButton("test1", "test1"),
            actionButton("test2", "test2")
        )
    })
    
    observeEvent(list(input$test1, input$test2),{
        req(input$test1!=0 | input$test2 !=0)
        session$reload()
    }, ignoreInit = TRUE,ignoreNULL = TRUE)
})

shinyApp(ui, server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM