Interactive Controls for Jupyter Notebooks

We often need to explore figures and data in Jupyter notebooks by observing it for different values of parameters involved. The obvious solution is to change the value of parameters in the code and then run it and repeat this process for the different values we are targeting. In practice, this process becomes inconvenient and frustrating as the number of parameters and the possible values for each parameter that we want to explore grows. One solution for this problem is Jupiter interactive controls which can be added by using Jupyter widgets.

Jupyter widgets can be used in a variety of situations:

  • Data/Figure exploration through altering parameters.
  • While presenting data in a jupyter notebook during the presentation.
  • Creating small data dashboards within jupyter notebooks.

Installations and setup required

To work out the programs presented in this article, one needs to install Python, Jupyterlab, ipywidgets, matplotlib, and numpy on the pc along with a browser (Chrome, Edge, Firefox, Safari, etc.). Once the Python interpreter is installed, others can be installed with any Python package manager like pip or conda. Here are the commands for pip –

For Windows:

py -m pip install --upgrade "jupyterlab", "matplotlib", "numpy", "ipywidgets"

For Linux/Mac:

python3 -m pip install --upgrade "jupyterlab", "matplotlib", "numpy", "ipywidgets"

Once all these are installed, go to the project folder/the folder in which you want to keep the jupyter files and open the command window (terminal/console) there. Run the following command to launch the jupyter notebook in browser with this folder as the project folder –

For Windows

py -m jupyter lab

For Linux/Mac

python3 -m jupyter lab

Interactive Controls in Jupyter Notebooks

This article explains the significance of interactive controls in Jupyter Notebooks and presents a few different methods of adding them to the notebooks for Python programming language. A list of basic controls/widgets and finally examples are provided to demonstrate all that is presented throughout this article. This article expects basic familiarity with Python and Jupyter Notebooks.

Similar Reads

Interactive Controls for Jupyter Notebooks

We often need to explore figures and data in Jupyter notebooks by observing it for different values of parameters involved. The obvious solution is to change the value of parameters in the code and then run it and repeat this process for the different values we are targeting. In practice, this process becomes inconvenient and frustrating as the number of parameters and the possible values for each parameter that we want to explore grows. One solution for this problem is Jupiter interactive controls which can be added by using Jupyter widgets....

Basic Interactive widgets in Jupyter Notebooks

Lots of widgets are available in ipywidgets for jupyter notebooks. The complete list can be obtained here on the official documentation. This section provides the syntax and usage of few basic widgets –...

Custom Interactive Controls in jupyter notebooks

...

Conclusion

...