Widgets#

The most common widgets, sliders, checkboxes, and dropdowns.

A full list of widget functionalities can be found in the ipywidgets documentation and the easiest way to get started using IPython’s widgets is by Interact.

Importing libraries and packages#

 1# Warnings
 2import warnings
 3
 4# Widgets
 5from ipywidgets import interact, interact_manual
 6
 7# Output
 8from bokeh.io import output_notebook
 9
10output_notebook()
11warnings.filterwarnings("ignore")
Loading BokehJS ...

Visualisation#

1# Creating a checkbox
2@interact(value=False)
3def checkbox(value=False):
4    print(value)
1# creating a dropdown
2options = ["Option1", "Option2", "Option3", "Option4"]
3
4
5@interact(value=options)
6def dropdown(value=options[0]):
7    print(value)
1# Creating a text input
2@interact(value="Input Text")
3def text_input(value):
4    print(value)
1# Multiple widgets with default layout
2options = ["Option1", "Option2", "Option3", "Option4"]
3
4
5@interact(select=options, display=False)
6def uif(select, display):
7    print(select, display)
1# Creating an int slider with dynamic updates
2@interact(value=(0, 100))
3def slider_integer(value=0):
4    print(value)
1# Creating a float slider 0.5 steps with manual update trigger
2@interact_manual(value=(0.0, 100.0, 0.5))
3def slider_float(value=0.0):
4    print(value)