Skip to content

Instantly share code, notes, and snippets.

@cecilialee
Last active June 21, 2019 13:30
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 cecilialee/b5def8b9e5c2b538687b63f07deef6ac to your computer and use it in GitHub Desktop.
Save cecilialee/b5def8b9e5c2b538687b63f07deef6ac to your computer and use it in GitHub Desktop.
Create a pop-up modal dialog prompting for user's confirmation. (Confirm / Cancel) #r #shiny
library(shiny)
shinyApp(
# ui ------------------------------------------------------------------------
ui = basicPage(
actionButton("skip", "Skip"),
textOutput("status")
),
# server --------------------------------------------------------------------
server = function(input, output) {
vals <- reactiveValues(data = NULL)
# create modal
skipModal <- function(failed = FALSE) {
modalDialog(
"Are you sure you want to skip this form?",
footer = tagList(
modalButton("Cancel"),
actionButton("confirm_skip", "Confirm")
)
)
}
# show modal
observeEvent(input$skip, {
showModal(skipModal())
})
# confirm skip
observeEvent(input$confirm_skip, {
removeModal()
vals$data <- "Skipped"
})
# output
output$status <- renderText({
if (is.null(vals$data))
"Not skipped"
else
vals$data
})
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment