Dash apps 🤝¶
This documentation page describes how you can integrate plotly-resampler in a dash application.
Examples of dash apps with plotly-resampler can be found in the
examples folder of the GitHub repository.
Registering callbacks in a new dash app¶
When you add a FigureResampler figure in a basic dash app, you should:
- Register the
FigureResamplerfigure its callbacks to the dash app.- The id of the dcc.Graph component that contains the
FigureResamplerfigure should be passed to theregister_update_graph_callbackmethod.
- The id of the dcc.Graph component that contains the
Code illustration:
# Construct the to-be resampled figure
fig = FigureResampler(px.line(...))
# Construct app & its layout
app = dash.Dash(__name__)
app.layout = html.Div(children=[dcc.Graph(id="graph-id", figure=fig)])
# Register the callback
fig.register_update_graph_callback(app, "graph-id")
# start the app
app.run_server(debug=True)
Warning
The above example serves as an illustration, but uses a global variable to store the FigureResampler instance;
this is not a good practice. Ideally you should cache the FigureResampler per session on the server side.
In the examples folder,
we provide several dash app examples where we perform server side caching of such figures.