Sphere
Log in Join
☆ 9

plotly dash callback reruns everything on any input

Dash 2.15, Python 3.11. I have a dashboard with 5 dropdowns and 3 graphs. Any single dropdown change triggers my one big callback that recomputes all 3 figures, which takes ~4 seconds because it re-queries pandas. I want only the affected graph to update. I know about dash.dependencies.Input vs State and multiple outputs, but it's getting messy. Is there a clean pattern for this - one callback per output, or use pattern-matching callbacks? Also is there a way to cache the intermediate results so switching back to a previous selection is instant?

⚑ Report

4 replies

☆ 0
F fern ·2026-11-12#1

Split into three callbacks, one per graph output, each depending only on the inputs that affect it. A single mega-callback is an anti-pattern. For the 4s recompute, cache with flask-caching: cache = Cache(app.server, config={'CACHE_TYPE': 'simple'}) and decorate the expensive data-loading function with @cache.memoize(). That way switching back is instant. Also consider dcc.Store to hold intermediate DataFrames in the browser so you don't re-query at all for some interactions.

⚑ Report
☆ 0
R regex ·2026-11-13#2

Splitting into 3 callbacks helped but two of the graphs share the same filtered DataFrame, so I'm computing it twice now. Where should that shared computation live? Can one callback write to a dcc.Store and the others read from it, or do I need a third callback in the chain?

⚑ Report
☆ 0
Y yaml ·2026-11-15#3

Yes - callback A takes the dropdowns and writes the filtered DataFrame to a dcc.Store (as JSON via to_json()), and callbacks B and C take that Store's data as Input. That gives a clean chain: inputs -> store -> figures, and the shared filter runs once. The store data has to be JSON-serializable, so use to_json(orient='records') and read back with pd.read_json. For large frames, store a parquet file server-side and put just a key in the Store.

⚑ Report
☆ 0
F ferret ·2026-11-17#4

Went with the Store approach plus @cache.memoize on the server-side load. Now a dropdown change updates in under a second and going back to a previous selection is instant. The chain 'inputs -> dcc.Store -> figure callbacks' is the pattern I was missing. If your data is big, cache server-side and store the cache key in the browser, don't ship megabytes of JSON to the client.

⚑ Report
Log in to reply.