How to open two shinyAlert popups in sequence, showing two different tables into themeselves

164 Views Asked by At

Here in attach my example piece of code that doesn't work.

If I #hide the first shinyalert, the second popup shows correctly the table.

I think the wrong behaviour depends on a IDs mismatch, but I wasn't able to write different IDs manually on the correct objects. Many thanks in advance.

library(shiny)

ui <- fluidPage(
    shinyalert::useShinyalert(),
    #action button to run the example
    mainPanel(shiny::actionButton(inputId = "elab", label = "Run the code...", class = "butt"))
)

server <- function(input, output) {
    #first popup the table appears correctly
    shiny::observeEvent(input$elab, {
        shinyalert::shinyalert(
            inputId = "sa1",
            title = "<h3>First popUp</h3>",
            type = "warning", html = TRUE, size = "l",
            text = shiny::div(id = "div1", DT::renderDataTable(DT::datatable(data = iris %>% dplyr::select(Species) %>% head(1)))
            )
        )
        print("execution after 1")

        #second popup appears whitout the table
        shinyalert::shinyalert(
            inputId = "sa2",
            title = "<h3>Second popUp</h3>",
            type = "error", html = TRUE, size = "l",
            text = shiny::div(id = "div2", DT::renderDataTable(DT::datatable(data = mtcars %>% dplyr::select(disp) %>% head(2))))
        )
        print("execution after 2")
    })

}
shinyApp(ui = ui, server = server)
0

There are 0 best solutions below