Using interactive widgets¶
You can use ipywidgets and FigureWidget in Notebooks to bring interactive controls such as sliders, buttons,
dropdowns, and text inputs. By connecting Python code to browser-based widgets, you can build dynamic visualizations,
parameter exploration, and interactive applications.
Installation¶
Runtime v2.6 and above¶
ipywidgets and anywidget are pre-installed. No extra setup is needed: skip straight to importing.
Runtime v2.5 and below¶
Install the packages at the top of your notebook before importing:
Run those cells once per session. After installation, proceed to the imports below.
Imports¶
For common helpers used in the examples below:
Basic controls¶
Slider¶
Dropdown¶
Checkbox¶
Button¶
Text input¶
Laying out widgets¶
Use HBox (horizontal) and VBox (vertical) to arrange controls:
FigureWidget (Plotly)¶
FigureWidget is a Plotly figure that supports live in-place updates, making it ideal for linking controls to a chart
without re-rendering the whole figure.
Prerequisite: anywidget must be installed.
Basic line chart¶
Supported widget types¶
| Category | Widgets |
|---|---|
| Numeric | IntSlider, FloatSlider, IntRangeSlider, FloatRangeSlider, IntText, FloatText, BoundedIntText, BoundedFloatText |
| Selection | Dropdown, SelectMultiple, RadioButtons, ToggleButtons |
| Boolean | Checkbox, ToggleButton |
| Text | Text, Textarea, Label, HTML |
| Button | Button |
| Display | Output, IntProgress, FloatProgress, Valid |
| Layout | HBox, VBox, Tab, Accordion |
| Date / Color | DatePicker, ColorPicker |
| anywidget | FigureWidget (Plotly) and other anywidget-backed libraries |
Notes¶
- Widgets require an active kernel to sync state. If you refresh the page, re-run the cell to restore the widget.
- While another cell is executing, interactive controls (sliders, dropdowns, buttons) are temporarily disabled to prevent state drift between the UI and the running kernel.
- Cache isn’t supported with different sessions.
Known unsupported ipywidgets¶
The following widgets show an “Unsupported widget” message:
- Play (PlayModel): Timer-based auto-increment not implemented.
- Image (ImageModel): Binary buffer support not implemented.
- FileUpload (FileUploadModel): Binary buffer and security review needed.