Re-use plotly plot if config did not change #1393
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR solves #1386 using
Plotly.react
instead ofPlotly.newPlot
when the config did not change. This allows usinguirevision
to keep the user state (zoom level etc.) while updating the data.The distinction whether the config changed is necessary because
Plotly.react
behaves badly if we passoptions.config
withresponsive=true
being set. But since it doesn't change when only updating data, we can still use the more efficientPlotly.react
in these cases.While being at this, I improved the update mechanism (implement the
updated
method instead of requiring to callupdate
from the server) and moved the default setting ofresponsive=true
to the client (simplifies the Python code, combines all config trickery in one place).This test code provides a button to update the data as well as one to update the config:
The plot remains responsive (i.e. fills the width of the container when resizing the window) and keeps the user state (e.g. zoom level) when updating the data. Only when the config changes (e.g.
displayModeBar
) the user state resets because the plot is re-created.