Skip to content

Instantly share code, notes, and snippets.

@hadley
Created September 12, 2019 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadley/8d9ee5ea7991b0e5c400320abb9468de to your computer and use it in GitHub Desktop.
Save hadley/8d9ee5ea7991b0e5c400320abb9468de to your computer and use it in GitHub Desktop.
modalContinue <- function(id) {
ns <- NS(id)
showModal(modalDialog(
"This is really important!",
"Are you sure you want to continue?",
footer = list(
actionButton(ns("yes"), "yes"),
actionButton(ns("no"), "no")
),
easyClose = FALSE
))
}
modalContinueServer <- function(id) {
module <- function(input, output, session) {
val <- reactiveVal(NULL)
observeEvent(input$yes, {
removeModal()
val(TRUE)
})
observeEvent(input$no, {
removeModal()
val(FALSE)
})
reactive(val())
}
callModule(module, id)
}
# -------------------------------------------------------------------------
ui <- fluidPage(
actionButton("go", "Go"),
textOutput("result")
)
server <- function(input, output, session) {
observeEvent(input$go, {
modalContinue("ok")
})
result <- modalContinueServer("ok")
output$result <- renderText(result())
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment