8.4 Confirming and undoing

  • for potentially dangerous actions, like deleting things

8.4.1 Explicit confirmation

  • create a dialog box with modalDialog()
modal_confirm <- modalDialog(
  "Are you sure you want to continue?",
  title = "Deleting files",
  footer = tagList(
    actionButton("cancel", "Cancel"),
    actionButton("ok", "Delete", class = "btn btn-danger")
  )
)

ui <- fluidPage(
  actionButton("delete", "Delete all files?")
)
server <- function(input, output, session) {
  observeEvent(input$delete, {
    showModal(modal_confirm)
  })
  
  observeEvent(input$ok, {
    showNotification("Files deleted")
    removeModal()
  })
  observeEvent(input$cancel, {
    removeModal()
  })
}

8.4.2 Undoing an action

More like waiting some time before acually performing the task and giving the user time to stop the action before it’s actually happening.

–> example app