Toggle Button Menu

Example showing how to construct a toggle button widget that can be used to select a cube dimension.


In [ ]:
import ipywidgets
import IPython.display
import iris

Load cube.


In [ ]:
cube = iris.load_cube(iris.sample_data_path('A1B.2098.pp'))
print cube

Compose list of options and then construct widget to present them, along with a default option. Display the widget using the IPython display call.


In [ ]:
coordinates = [(coord.name()) for coord in cube.coords()]

dim_x = ipywidgets.ToggleButtons(
    description='Dimension:',
    options=coordinates,
    value='time')

IPython.display.display(dim_x)

Print selected widget value for clarity.


In [ ]:
print dim_x.value