Polling Jupyter widget UI events in runtime
Contents
Let’s look at a code snippet in the Jupyter Notebook:
|
|
IntSlider
is an interactive Jupyter Notebook widget. When the user interacts with the slider, the slider value should change.
However, if you run the above codes, you will find that the printed value of the slider won’t change at all – it will be stuck at its initial value.
In fact, the UI elements won’t be updated until all code blocks are finished executing. In other words, the update of the UI elements is blocked by the execution of any code block.
In order to poll the states of UI elements inside a running loop, we can use the jupyter-ui-poll library. The modified codes are as follows:
|
|