Example scenario / steps to reproduce:
- App has several plots, all of which have the same x-axis coordinate units
- When one plot is rescaled (x-axis range modified, e.g. zoom in), all plots should rescale the same way
- Rather than rebuild each plot, we can now implement a callback using
Patch
. This way, the heavy lifting of initially rendering the plots happens only once, and when a plot is rescaled, only the layout of each plot is updated.
@callback( output=[Output(dict(type=‘plot’, id=plot_id), ‘figure’, allow_duplicate=True) for plot_id in plot_ids))] inputs=[Input(dict(type=‘plot’, id=ALL), ‘relayoutData’], prevent_initial_call=True ) def update(inputs): plot_updates = [Patch() for _ in plot_ids] for p in plot_updates: p.layout.xaxis.range = get_range(dash.callback_context.triggered) # implemented elsewhere return plot_updates
Unexpected behavior:
Upon rescale of a plot, only some of the other plots actually update in the UI. Which plots update in response to a rescale is inconsistent and seemingly random (sometimes they all update and the app appears to work as I expect, sometimes only a few of them update, etc). I have verified that the callback/Patch does update the range property in every figure data structure, so it seems like there’s just some inconsistency with listening for the update (or maybe I made an error with how I’ve implemented this).
Happy to provide a screen recording if it would help.
dash 2.9.3
dash-bootstrap-components 1.4.1
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table 5.0.0