dcc_confirmdialog
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 dcc_confirmdialogprovider
for an easier way to display an alert when clicking on an item.
using Dash
external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]
app = dash(external_stylesheets=external_stylesheets)
app.layout = html_div([
dcc_confirmdialog(
id="confirm",
message="Danger danger! Are you sure you want to continue?",
),
dcc_dropdown(
options=[
Dict("label" => i, "value" => i)
for i in ["Safe", "Danger!!"]
],
id="dropdown"
),
html_div(id="output-confirm")
])
callback!(app, Output("confirm", "displayed"),
Input("dropdown", "value")) do value
if value == "Danger!!"
return true
end
return false
end
callback!(app, Output("output-confirm", "children"),
Input("confirm", "submit_n_clicks")) do submit_n_clicks
if !(submit_n_clicks isa Nothing)
return "It wasnt easy but we did it $(submit_n_clicks)"
end
end
run_server(app, "0.0.0.0", debug=true)
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
(String; 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
(String; optional):
Message to show in the popup.
submit_n_clicks
(Real; default 0
):
Number of times the submit button was clicked.
submit_n_clicks_timestamp
(Real; default -1
):
Last time the submit button was clicked.
cancel_n_clicks
(Real; default 0
):
Number of times the popup was canceled.
cancel_n_clicks_timestamp
(Real; default -1
):
Last time the cancel button was clicked.
displayed
(Bool; optional):
Set to true to send the ConfirmDialog.