JupyterLab Widgets Extension
`jupyterlab-widgets` is the JupyterLab frontend extension that provides the necessary framework for rendering interactive `ipywidgets` within JupyterLab notebooks and interfaces. It enables the rich interactive experiences defined by the core `ipywidgets` Python library. As of version 3.0.16, this extension is compatible with JupyterLab 3 and 4, and for many modern setups, it is automatically handled or included when `ipywidgets` is installed.
Warnings
- gotcha It is important to distinguish between `jupyterlab-widgets` and `ipywidgets`. `ipywidgets` is the core Python library for defining and creating interactive widgets, while `jupyterlab-widgets` is the JupyterLab frontend extension responsible for rendering these widgets. Users primarily interact with `ipywidgets` in their Python code.
- breaking JupyterLab version compatibility for the `jupyterlab-widgets` extension has historically required specific installation steps. For JupyterLab 1 or 2, manual `jupyter labextension install` was often necessary. JupyterLab 3.0+ and `ipywidgets>=7.6.0` typically handle the extension automatically, but compatibility issues can still arise, especially with major JupyterLab upgrades (e.g., to JupyterLab 4).
- gotcha If JupyterLab and your Python kernel (with `ipywidgets`) are installed in separate virtual environments (e.g., using different Conda environments), `jupyterlab-widgets` must be installed in the environment where JupyterLab is running, and `ipywidgets` must be installed in each kernel's environment that will use widgets.
Install
-
pip install jupyterlab-widgets -
pip install ipywidgets
Imports
- Button
from ipywidgets import Button, IntSlider, interact
- display
from IPython.display import display
Quickstart
from ipywidgets import IntSlider, interact
from IPython.display import display
def f(x):
print(x)
# Create a slider widget
slider = IntSlider(min=0, max=100, step=1, description='Value:')
display(slider)
# Or use interact for quick interactive functions
interact(f, x=10);