New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plots duplicated when saving notebook repeatedly #107
Comments
Thanks for the bug report. Why do we even need all of these checks? Isn't it enough to just check whether the image already exists? Or actually, why do we check at all? When does it happen that we call |
I'm not at all an expert, but to attempt to answer these questions:
Yeah, I'm wondering the same thing. Changing the conditional from: These set of conditionals were added all at once here: be19059
This function is called from the javascript output of the jupyter cell, which will have:
I see it being called each time the page is reloaded, so I believe it must be idempotent if it has run before and modified the notebook document already. |
Thanks for looking into this.
So we need the check whether the image is already present. However, I think we only need to check for the image, and not the js. So Maybe @ellisonbg can help us why the original condition was written in the way it was. |
Yeah, this logic was super subtle and I am not surprised we have bugs in it. I can describe the different situations where this code gets called and what the desired behavior is:
Question - does the additional image appear when the notebook is saved or when it is reopened after a save. I am somewhat wondering if there has been a change in how the notebook itself of behaving in these situations. I don't remember why that |
I actually can't reproduce the error in https://github.com/vega/ipyvega/blob/master/notebooks/VegaLite.ipynb. Can you help me create a small test case (ideally without Altair)? |
Thanks for having a look! I can see the same behavior without Altair if I do:
Click save on the notebook, then reload the page; you should see an additional copy of the plot each time you do so. I had to take the above approach (displaying the plot and also returning it so it's displayed in the Out[] area) to reproduce, but you also see this behavior in altair even if not displaying twice this way. |
Thank you for the test case. I removed the |
I've noticed an issue, where each time a (classic) jupyter notebook is saved, any vega plot gets duplicated an additional time.
In troubleshooting, I can see that this line:
ipyvega/src/index.ts
Line 61 in 8c9bba9
never triggers, causing a PNG to get appended to the outputs each time. It appears that the if condition doesn't trigger because
imgIndex === jsIndex + 2
. Looking at the saved notebook, this is caused by an empty text/plain output nestled between the javascript and PNG outputs:In case it helps, here's a screenshot after saving (and reloading) the notebook multiple times:
I'm hoping this might be enough to point towards a potential solution. Thanks!
The text was updated successfully, but these errors were encountered: