Last active
June 21, 2019 13:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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