Black Lives Matter. Please consider donating to Black Girls Code today.

Feature request - asynchronous notifications

I think it would be nice to have some mechanism for asynchronous user notification integrated into the dash core components.
The component could be build on top of the react-notification-system

With notifications it would be much easier to do error handling and provide additional information to the user.

What do you think about this idea?

1 Like

I would very much welcome such functionality!

I think that there are a couple of issues at play here.
1 - Customizable error handling UI. Right now, it isn’t possible to display backend error messages to the front-end (but it should be)
2 - Asynchronous messages - communicating messages (to multiple outputs) to the web app while a callback is being executed. For example, something like:

@app.callback(
    [Output('component-1', 'children'), Output('component-2', 'children')],
    [Input('input-1', 'value'), Input('input-2', 'value')])
def update_outputs(output1, output2, input1, input2):
    output1.set_value('Loading...')
    result = perform_expensive_computation(input1, input2)
    output2.set_value(result)
    output1.set_value('Done')

This would be primarily useful for loading messages.
3 - Customizable UI on a per-component basis while callbacks are being executed (“loading state”). (see 📣 Dash Loading States for an interim solution).
4 - UI components for displaying “messages” like the react-notification-system.

4 will be most useful once 1 and 3 are done. I’m considering proposals like 2 for the next version of Dash but I’m not yet sure how useful it will be outside of the loading state and error state use cases.

1 Like

hi @chriddyp, coming from shiny I do miss this functionality in Dash quite frequently. (mainly 2) for enabling very interactive feedback while callbacks are processing, updating stats, messages, gives a very cool feel to the app, also without extensive code needed, just ocasional log/notify messages in callbacks code)

Don’t know if today there’s a better way in shiny, but the solution I was using at the time, was around shiny sendCustomMessage function (server-> client). I rendered the html from any R shiny object, then update on client with custom
shiny handler:

(https://shiny.rstudio.com/articles/js-send-message.html)

R code (server)

updateUI=function(session,id,elem)
{
session$sendCustomMessage(type = ‘updateUI’, message = list(id = id, html=paste0(elem)) )
}

Added javascript handler

Shiny.addCustomMessageHandler(“updateUI”,

function(message) {

elem=document.getElementById(message.id);

elem.outerHTML=message.html;

}

);

Usage:

updateUI(session,“progress”,
paste0(gsub("","",infoBoxOutput(“progress”)),
valueBox(title, detail, icon = icon(“info”),
color = “green”,width = NULL)
,"")
)