Announcing Dash Bio 1.0.0 🎉 : a one-stop-shop for bioinformatics and drug development visualizations.

How to make long_callback work with MultiPageDashApp?

I tried to create a multi-page Dash app which use “@long_callback” in a separated file under pages fold, code copied from example from dash-labs/ at main · plotly/dash-labs · GitHub

I want to replace @callback with @long_callback to make the function run asynchronously, but I don’t know how to achieve it. Any help?

Output(“histograms-graph”, “figure”),
Input(“histograms-mean”, “value”),
Input(“histograms-std”, “value”),
def display_color(mean, std):
# data = np.random.normal(mean, std, size=500)
data = fetch_from_database()
fig = px.histogram(data, nbins=30, range_x=[-10, 10])
return fig

Hi @vnnw and welcome to the Dash community :slight_smile:

Currently long_callback requires the app object, ie @app.long_callback. It will cause circular imports if you try to include it in the pages/ folder. However, it’s still possible to use it in this multi-page environment.

The workaround is to put the @app.long_callback in the file. The layout and any other @callbacks can be in the pages/ folder.

I’ll post an example to dash-labs shortly.

1 Like