After a kernel restart widgets are not preserving the user-selected inputs. Here is the use case:
I create a notebook with multiple widgets, and save the notebook. After a kernel restart, if I run the notebook again, the widgets doesn’t retain the values and I am forced to enter the values again. If I save widget state(An option from Settings), then the notebook is loaded with the values I selected. But, if I run the cells, the values are cleared.
This looks like a common use case. How can I make widgets to preserve the user entered values?
by default the widget state is not stored on save. you can manually save notebook widget state or configure Lab’s settings so Jupyter Widgets will Save widget state in notebooks.
Once the widget state is saved, I can load the notebook and see the values I entered. If I run the cell, then the values are getting cleared. I want to run the cells with values whatever I entered.
Say if a text box is created with default value as ‘Test’ and I changed the value to ‘Test Passed’. I saved the notebook. After a kernel restart, If I run the same cell again, then ‘Test Passed’ value is cleared and the default value ‘Test’ is displayed.
Instead of me typing ‘Test Passed’ value again, I want the widget to remember the value I entered. Is it possible to do that in Jupyter notebooks?
well that is a different kind of ask. i don’t you’ll find those abilities in core
IPython. someone might have written an extension that does this. maybe
ipyflow has some of these features.
Thank you. Zeppelin currently has this feature and this is a common use case for us in our org. We create notebooks with preselected widget values and give the notebook to someone else who changes only a few widget values or maybe just the dataset they’re running it against. We want the widget values to be retained no matter how many times the notebook is imported/exported.
Could you share how zeppelin does this? How does it link the initial value with the code that is executing in the notebook.
This is how Zeppelin does it: zeppelin/GUI.java at 11052f6fb435c812788a5f30211b9d71842f9182 · apache/zeppelin · GitHub
Zeppelin checks to see if there is already a value, if it is there it uses that value. And if there isn’t it uses the default.