Plotly.js to Dash migration boundary: can dcc.Graph and client-side charts coexist during a zero-downtime cutover?
0 reputation · 04 Mar 2024, 12:16 UTC
0 reputation · 04 Mar 2024, 12:16 UTC
A small application currently renders interactive charts client-side with Plotly.js. The goal is to migrate to Python Dash, which wraps Plotly.js through its dcc.Graph component, without taking the application offline. The plan is a gradual rollout where some views are served by Dash callbacks while others still use the existing JavaScript rendering.
Dash runs as a separate server process, so during the transition both rendering paths must be deployed and routed in parallel. Interactivity currently implemented in JavaScript (hover behavior, click events, zoom state) would move into Dash callbacks, and it is unclear which of those behaviors translate directly and which need reimplementation. State that previously lived in the browser would need a server-side equivalent. There is also a known risk of rendering inconsistencies when the Plotly.py/Dash version pair does not match the Plotly.js feature set the existing charts rely on; this should be verified against current release notes before rollout.
dcc.Graph) behind feature flags a sound approach for zero-downtime cutover, or does it introduce state-consistency problems between the two?30775 reputation · 04 Mar 2024, 21:29 UTC
Yes, dcc.Graph and client‑side Plotly.js can coexist during a zero‑downtime cutover, provided you:
Both rendering engines ultimately consume a Plotly figure JSON. The Dash dcc.Graph component is a thin wrapper that injects the same Plotly.js library into the browser, so if the figure and library versions match, the visual output is identical. Feature flags allow you to serve one path to a subset of users while the rest continue on the legacy path, giving you a controlled, incremental rollout.
Client‑side interactions that modify chart state (e.g., zooming, clicking a legend item) are normally handled entirely in the browser. In Dash, those interactions must be captured by a callback (e.g., relayoutData, clickData) and sent back to the server. If the legacy path updates the chart without reflecting those changes server‑side, the two views will diverge, confusing users and breaking metrics. The safest approach is to replicate the exact state changes on the server for any path that will eventually use Dash callbacks.
relayoutData and hoverData.restyle or relayout APIs may require a custom Dash component or a hybrid approach.Dash bundles plotly.js via the plotly.py dependency. The plotly.js version shipped with Dash is pinned to the plotly.py release. Verify that:
plotly.js Plotly.version string matches the one in plotly.py (e.g., 5.22.0).USE_DASH) to the request context. Route the HTML template to include either the legacy plotly.js script or the Dash dcc.Graph component.dcc.Graph for Dash. Keep the schema identical.Plotly.relayout events) and send it to the server via an AJAX endpoint. Update the Dash callbacks to read that state instead of relying on the browser.To finalize the compatibility gate, we need the exact plotly.js version currently used in the legacy application. Please provide that version string so we can verify it against the plotly.py release bundled with Dash.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.