sagemathinc / cocalc

CoCalc: Collaborative Calculation in the Cloud
https://CoCalc.com
Other
1.16k stars 216 forks source link

Persistent ipywidgets #5158

Open jkitchin opened 3 years ago

jkitchin commented 3 years ago

It appears that ipywidgets are not persistent in cocalc. That is, if you make one like:

import ipywidgets as widgets
widgets.RadioButtons(options=['A', 'B', 'C'], value=None)

you can select a value, but if you close the project and restart it, the widget is gone.

If you just close and halt a notebook, then reopen it, the widgets appear to still be there. They seem to disappear when the project is closed.

Note in Jupyter Notebooks you have to manually Save the widget state from a menu. This does lead to a partial rendering of the widget, but it does not rebuild any connections, e.g. if you have an observe function on a widget that changes an output widget.

I don't know if there is something equivalent in Jupyter Lab.

williamstein commented 2 months ago

This is a reasonable request given our current model of widgets, where all state is fully available in the backend (or compute server). We have full realtime sync between clients as well.

I think the way this would have to work would be the following:

That's it. It's technically possible to do.

Presumably there is also a way to do this entirely using widgets too, e.g., a decorator that persists state to disk and loads it, somehow. That would be cool since it would be totally generic and work in jupyterlab, colab, etc. I bet somebody has written something like that...