Repository navigation
Redraw a figure in JupyterLab when its output is updated - #5865
Open
AllenDowney wants to merge 2 commits into
Open
AllenDowney wants to merge 2 commits into
AllenDowney wants to merge 2 commits into
Conversation
The mime renderer's renderModel returned early whenever it already had a graph, so update_display_data (for example IPython's DisplayHandle.update) never changed the figure. Redraw when the figure in the new model differs from the one drawn; keep returning early when it's the same, as when createGraph stores the PNG in the model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Link to issue
Closes #3053, which was closed as stale in 2024; it still happens with jupyterlab-plotly 7.1.0.
Description of change
When a kernel updates a displayed figure with
update_display_data(for example IPython'sDisplayHandle.update), JupyterLab callsrenderModelagain on the existing renderer, andrenderModelreturned early because it already had a graph, so the figure never changed. Now it redraws (withPlotly.react, throughcreateGraph) when the figure in the new model differs from the one it drew. It still returns early when the figure is the same, which is what happens whencreateGraphstores the PNG of the figure in the model.Demo
The example from #3053, in JupyterLab 4 with plotly 7.1.0:
Before: the first bar stays at 20. After: it goes to 10, 5, then 1.
This also fixes animations in the Octave kernel xeus-octave (its issue #2), which draws figures with this renderer and updates them on each
drawnow; checked in JupyterLite with an 8-frame loop: before, the plot stays on the first frame; after, it steps through all eight.Testing strategy
I didn't find tests for the mime renderer to extend, so I tested by hand: the two examples above, before and after, in JupyterLab 4 and in JupyterLite 0.8, checking the plot's data in the page; and a plot with no updates still renders.
Guidelines