Interactive widgets while executing long-running cell

Hi,

I want to share a small library I developed that allows interaction with ipywidgets inside lab or notebook environments while executing a long-running cell.

I chose the name jupyter-ui-poll. Library is open source, on github, and available for installation from PyPi.

So why is it needed?

By default UI events are not processed while code inside a notebook cell is executing, Javascript events do run, but not python callbacks. This makes it impossible to implement user interfaces that block execution of the rest of the notebook while waiting for input from the user.

This behaviour is often desirable however. In geospatial applications in particular selecting a region on a map at the start of the notebook, then running the rest, is a commonly requested feature. While this is possible to achieve with current tools, the experience is a bit sub-par, as it requires instructing the notebook user to not execute subsequent cells until desired input is provided.

I wanted to be able to write notebooks that use highly interactive user inputs, like ipyleaflet, while still maintaining a typical linear workflow. And I wanted to be able to run those notebooks with Run All without any issues.

While researching on how to achieve this I came across ipython_blocking library that addresses similar issue. Ultimately it did no quite suit my needs, but it did provide a starting point for my own implementation, so I thought it’s important to reference it.

You can install it with pip:

pip install jupyter-ui-poll

Or play with it in binder.

4 Likes