-
Notifications
You must be signed in to change notification settings - Fork 225
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
embed and close button #150
Comments
If I understand correctly, something like this is not just nice to have, it is essential if the widget is going to be an acceptable replacement for the notebook backend. Without it, open figures pile up, holding memory, and eventually triggering the matplotlib "many open figures" warning. |
I agree, I sometimes work in with figures of quite large datasets (images) and in the Notebook backend I can close and embed a static picture instead of the widget. It is not just nice for export and later viewing, it also helps freeing up memory. |
As discussed in the linked PR none of us have figured out a good way to do this yet. An alternative that would be helpful (for me at least) would be to have an equivalent button/method that created a new cell below the one in which the figure is displayed and then embedded the png of the figure as an attachment to the markdown cell. I think this should be possible through the I'm pretty sure this is possible in JupyterLab and not so sure about in the notebook. Though given that |
I think for the jupyterlab the code would look something like this (based on https://github.com/QuantStack/jupyterlab-snippets/blob/master/src/index.ts):
except that the final line should make use of https://jupyterlab.readthedocs.io/en/stable/api/classes/cells.markdowncell-1.html#updatecellsourcewithattachment which is what jlab uses internally when you paste an image from the clipboard. |
Wait, actually the fully proper solution of modifying the output area may be possible in jlab at least by using the https://jupyterlab.readthedocs.io/en/stable/api/interfaces/outputarea.ioutputareamodel-1.html api. I think that previous attempts at this have stalled out because python methods like Potentially though this is something that could/should be implemented by ipywidgets. |
@martinRenou @tacaswell thoughts on starting to make use of jlab specific apis? |
I find the solution to update the cell output better than the one adding a new cell. We would still need to figure out a strategy for that, when should we update the display? Only when the figure is closed? When the Notebook is saved? |
Same, the new cell was just the first thought I had as that's what I've been doing manually.
I think as a first step we could have an embed button that triggers it per view like in your PR and also when the figure is closed all views should embed themselves. Although I'm not exactly sure how that would work if they're incorporated in a larger widget layout :/ Then separately: Whatever code in ipywidgets that renders the message when a view doesn't have a model (the |
I am not sure this would be possible on a per-view basis.
This workflow would not work. But I suppose it's fine.
IMO we need to not rely on ipywidgets anymore when the embed button has been pressed. Widget models are not saved in Notebooks by default, but raw images are so we need to replace the widget output entirely with a raw image. My PR was wrong in that sense. |
What would you think of embedding raw images automatically when saving the Notebook? We would need to hook to the classic Notebook saving and the JupyterLab save event (if there is such an event). |
There is a jlab save event. That is how we save widget state on save. |
Thanks a lot Jason. That will be useful. I guess the cleanest thing to do would be to look for the checkbox that says "save widget state" state, if it's checked, we don't do anything and let ipywidgets save the widget state, otherwise we replace the widget with a raw image. |
That sounds reasonable - you either get a live snapshot, or a "dead" image one. Would that require a kernel execution? I'd like to think about how to make this a more general feature of widgets. We've talked for a long time about having a widget-level "snapshot" or "html" function that would return static html representing the current widget state we could embed as an output in the document. |
It would also be great to think about the problem of communicating that the output does not necessarily represent the code just above it. Typically, the notebook encourages the belief that the code just above an output will reproduce that output (especially if the notebook is run in order). Dynamic outputs (a feature of Jupyter itself) violate that assumption, and ipywidgets does too (either the user could have interacted with it directly, or a later cell can change the output). In the context of reproducibility and communication, it would be great to convey to the user somehow that the output may not come directly from the cell above it. |
Just for heads up, I made an attempt to implement this for JupyterLab: #294 It does not work though, I am trying to overwrite the cells |
It would be really nice to have an 'embed and close' button in the toolbar, which closes the figure canvas, removes the widget and embeds the corresponding png into the notebook. That way, the figures will also persist when the notebook is closed and opened again etc.
The text was updated successfully, but these errors were encountered: