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?

2 Likes

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:

(Shiny - How to send messages from the browser to the server and back using Shiny)

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)
,ā€œā€)
)