Skip to content

Instantly share code, notes, and snippets.

@hadley hadley/modal-module.R Secret
Created Sep 12, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.