ipywidgets
ipywidgets copied to clipboard
widgets.HTML (and HBox) do not save output after page reload or ipynb file re-open
Description
I run widgets.HTML in Jupyter notebook (file.ipynb) and output looks fancy. When I reload page or when I close/re-open Jupyter notebook fancy output not saved, but HTML(value=... ) shown in output cell instead of expected text.
Reproduce
- create ipynb file with this code in cell: import ipywidgets as widgets widgets.HTML(value="Hello World")
- run ipynb file and expect to see fancy (formatted) test output
- save ipynb file
- close ipynb file
- open ipynb file
- I see in the output instead of fancy text: "HTML(value='Hello World')"
- to get again fancy output I need to run the cell again. I need to have outputs in all (and in HTML widgets outputs also) cells after file re-opened, because some cells in same ipynb can take hours to run. It also seen in HBox widgets (output not saved and after re-open). I did not check in other widgets.
Expected behavior
When close and re-open notebook, cells outputs has to be the same before I closed notebook (file.ipynb).
Context
- ipywidgets version 7.6.3
- Operating System and version: Linux
- Browser and version: Chrome, Version 96.0.4664.110
If using JupyterLab
- JupyterLab version: Version 2.2.6
jupyter labextension list JupyterLab v2.2.6 Known labextensions: app dir: /opt/conda/share/jupyter/lab @bokeh/jupyter_bokeh v2.0.4 enabled OK @jupyter-widgets/jupyterlab-manager v2.0.0 enabled OK @jupyterlab/cellone-extension v0.1.4 enabled OK @jupyterlab/explorer-extension v0.2.18 enabled OK @jupyterlab/fasta-extension v2.0.0 enabled OK @jupyterlab/geojson-extension v2.0.1 enabled OK @jupyterlab/git v0.24.0 enabled OK @jupyterlab/katex-extension v2.0.0 enabled OK @jupyterlab/mathjax2-extension v2.2.4 enabled OK @jupyterlab/mathjax3-extension v3.0.0 enabled OK @jupyterlab/oracle-splash-screen v0.1.0 enabled OK @jupyterlab/templates-extension v0.2.5 enabled OK @jupyterlab/toc v4.0.0 enabled OK @jupyterlab/vega5-extension v2.2.0 enabled OK @lckr/jupyterlab_variableinspector v0.5.1 enabled OK jupyter-leaflet v0.13.0 enabled OK jupyterlab-plotly v4.8.2 enabled OK nbdime-jupyterlab v2.0.2 enabled OK plotlywidget v4.8.2 enabled OK
I think you might need to check the "Save Widget State" or similar option in the menu in Lab.
hi! I used this menu as you suggested. In Jupyterlab it is "Settings -> Save Widget State Automatically". Result the same. when reload page or re-open Jupytelab notebook result not persist.
- Check menu item to Save widget sate:

- run code:

- reload page (or re-open Jupyterlab notebook):

Fancy formatting not persist in output cell.