Ipywidgets Widgets Values Not Changing
Solution 1:
This code doesn't work as intended in a normal notebook server, so probably won't work in Azure either. I suspect you need a thread process to read from the updated widget. Try this and see if you get anything printing in Azure Notebooks as you change the text field.
import time
import ipywidgets as widgets
from IPython.display import display
w = widgets.Text(disabled=False)
display(w)
defprint_text(widget):
print(widget['new'])
w.observe(print_text, names='value')
Solution 2:
The problem is that communication between widgets and the Python kernel is asynchronous and confusing.
time.sleep(...)
in the cell only blocks the Python interpreter and does
not allow the widget Javascript implementation to send the changed value to the Python
kernel (because the Python kernel is blocked and not doing anything).
If you create the widget and then modify the widget text entry and then evaluate
w.value
in the next cell interactively you will see the changed value.
See further discussion here (look for "async"):
https://github.com/AaronWatters/jp_proxy_widget/blob/master/notebooks/Tutorial.ipynb
In general if you want to force the Python interpreter to see some value sent from the Javascript widget implementation the Javascript side must call back to the Python interpreter in some way and the Python interpreter cannot be blocked by sleep or any other such mechanism.
Post a Comment for "Ipywidgets Widgets Values Not Changing"