-
Notifications
You must be signed in to change notification settings - Fork 949
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
saving static HTML with embedded widgets from Jupyter Lab and clearing widget state #2563
Comments
Can you clear widget state by closing all the widgets, then saving the file (with the save state automatically)? If you save state automatically, and make sure there are no active widgets, it should clear state. Alternatively, you might be able to just restart your kernel and save, since I think it actually only saves live widgets. |
Hi @jasongrout, I tried the following:
However, I was able to clear the widget state by restarting the notebook kernel. It would be nice to have the "clear widget state" and "save widget state" buttons from the Jupyter notebook - but restarting the kernel appears to work. I was looking into why the widget was not rendering when it was saved using File > Export Notebook to HTML. I made a branch that has two versions of the Jupyter Notebook HTML, one saved using It appears that the only difference between the HTMLs are under NBConvert HTML
Export Notebook to HTML
|
Once you create widgets, they exist as state, even if they aren't displayed. Until you explicitly close the widgets programmatically, or restart your kernel, they are considered live widget state, and so will be saved automatically. That's why the file stayed the same size in step 4.
A bit of background: Part of the design goals here were to resolve a lot of confusion that happened in the classic notebook around those options (#1866, #2012, #1632). When we designed this jlab experience, we had to make a choice for when the setting was not selected: should it clear the existing state, or leave it alone. We chose to leave it alone as the more predictable and expected behavior. How about a new menu item like "clear live widget state" which closes all the live widgets. This essentially is like restarting from a widgets perspective (all widgets would then disappear), and then a save will save an empty state (presuming you have "automatically save widget state" checked). |
That's odd that those are different. The "export notebook to html" one looks off. My guess is that diving into the way nbconvert is invoked in the server from that menu item may turn up the cause there - perhaps it's not doing the exact equivalent of your command line option. |
Thanks @jasongrout for the help. Clearing Widget State
That would be a good feature in my opinion. In my current workflow I often re-run cells (implicitly closing the widget) but I guess their state still exists since I haven't closed them programmatically (is there documentation for how to close programmatically?). Embedding Widget into HTML From Jupyter LabIn terms of getting jlab to save with HTML properly, do you think I should raise an issue in the https://github.com/jupyterlab/jupyterlab repo? Also, I confirmed that the two lines assigning |
Yes: https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Basics.html#Closing-widgets
That sounds like the right place to open an issue for this. |
Thanks, I'll raise these issues on the Jlab repo:
and close this one. |
That should be an issue here. Can you open a new issue in this repo focused on that? |
Thanks, I raised it here #2565 I also raised the issue here jupyterlab/jupyterlab#7262 |
A typical workflow we have with the widget we're developing (https://github.com/ismms-himc/clustergrammer2) is to load data, normalize, generate one or more interactive heatmap widget views of the data, and finally save the notebook with the widget state and export a static HTML notebook. This last step is useful for sharing results with collaborators who are not running a notebook (e.g. sending the static HTML file over an email).
This process works in the Jupyter notebook, but I haven't got it completely working in Jupyter Lab. We're now able to save the widget state in Jupyter Lab (see jupyterlab/jupyterlab#5235, and #2063 (comment)) using "Save Widget State Automatically" setting but there are two issues:
I am able to use nbconvert (5.3.2.dev0 see jupyter/nbconvert#636) in the Jupyter Lab terminal to generate a static HTML file with an embedded widget by running
My local laptop has:
Jlab: 1.0.4
ipywidgets: 7.5.1
nbconvert: 5.3.2.dev0
The text was updated successfully, but these errors were encountered: