How to close embedded modalDialog

2019-07-27 12:46发布

问题:

I have modalDialog embedded into other modalDialog. When I run modalButton both of them closed. How to close only embedded modalDialog?

Now : Code :

library(shiny)

shinyApp(
  ui <- fluidPage(
    actionButton("one","Press")  
  ),
  server <- function(input, output,session) {
    observeEvent(input$one,{
      showModal(modalDialog(            
        actionButton("two","Press 2"),
        footer = tagList(
          modalButton("Cancel")
        )))
    })
    observeEvent(input$two,{
      showModal(modalDialog(
        "OKAY",
        footer = tagList(
          modalButton("Cancel")
        )))
    })
})

Need :

回答1:

Im not sure what you want to display in modal but maybe you can have a look at the sweetalertR package :

 library(shiny)
library(sweetalertR)
shinyApp(
  ui <- fluidPage(
    sweetalert('#one',
      title = "Are you sure?",
      text = "Press here for some magic",
      type = "warning",
      showCancelButton = TRUE,
      confirmButtonColor = '#DD6B55',
      confirmButtonText = 'Yes, Confirm!',
      closeOnConfirm = FALSE,
      evalFunction = 'function(){swal("OKAY!", "Thank you PorkChop!", "success")}'
    ),
    actionButton("one","Press")  
  ),
  server <- function(input, output,session) { })