dccConfirmDialog

dccConfirmDialog is used to display the browser's native "confirm" modal, with an optional message and two buttons ("OK" and "Cancel"). This ConfirmDialog can be used in conjunction with buttons when the user is performing an action that should require an extra step of verification.

See dccConfirmDialogProvider for an easier way to display an alert when clicking on an item.

library(dashCoreComponents)
library(dashHtmlComponents)
library(dash)

app <- Dash$new()

app$layout(
  htmlDiv(
    list(
      dccConfirmDialog(
        id='confirm',
        message='Danger danger! Are you sure you want to continue?'
      ),

      dccDropdown(
        options=lapply(list('Safe', 'Danger!!'),function(x){list('label'= x, 'value'= x)}),
        id='dropdown'
      ),
      htmlDiv(id='output-confirm1')
    )
  )
)

app$callback(
  output = list(id = 'confirm', property = 'displayed'),
  params=list(input(id = 'dropdown', property = 'value')),
  function(value){
    if(value == 'Danger!!'){
      return(TRUE)}
    else{
      return(FALSE)}
  })


app$callback(
  output = list(id = 'output-confirm1', property = 'children'),
  params=list(input(id = 'confirm', property = 'submit_n_clicks')),
  function(n_clicks, value) {
    if(length(submit_n_clicks) == FALSE){
      sprintf('It wasnt easy but we did it %s', str(submit_n_clicks))
    }
  })

app$run_server()

ConfirmDialog Properties

Our recommended IDE for writing Dash apps is Dash Enterprise's Data Science Workspaces, which has typeahead support for Dash Component Properties. Find out if your company is using Dash Enterprise.

id (character; optional): The ID of this component, used to identify dash components in callbacks. The ID needs to be unique across all of the components in an app.

message (character; optional): Message to show in the popup.

submit_n_clicks (numeric; default 0): Number of times the submit button was clicked.

submit_n_clicks_timestamp (numeric; default -1): Last time the submit button was clicked.

cancel_n_clicks (numeric; default 0): Number of times the popup was canceled.

cancel_n_clicks_timestamp (numeric; default -1): Last time the cancel button was clicked.

displayed (logical; optional): Set to TRUE to send the ConfirmDialog.