ToggleGroup#

Download this notebook from GitHub (right-click to download).


import panel as pn
pn.extension()

A ToggleGroup is a group of widgets which can be switched ‘on’ or ‘off’.
This widget is a thin wrapper for using either a CheckButtonGroup, CheckBoxGroup, RadioButtonGroup or RadioBoxGroup to select between a single or multiple given values.

For more information about listening to widget events and laying out widgets refer to the widgets user guide. Alternatively you can learn how to build GUIs by declaring parameters independently of any specific widgets in the param user guide. To express interactivity entirely using Javascript without the need for a Python server take a look at the links user guide.

Parameters:#

For layout and styling related parameters see the customization user guide.

Core#

  • widget_type (str): Two types of widgets are available: button (default) and box

  • behavior (str): Two different behaviors are available: check (default) and radio

As the ToggleGroup class is just a Factory for other different widget types, the above parameters cannot be changed or set after instantion. All additional given parameters are passed through to the constructor of the resulting widget class.

The different parameter combinations and the resulting widget type are shown in the following table.

widget_type

behavior

Resulting Widget

button

check

CheckButtonGroup

button

radio

RadioButtonGroup

box

check

CheckBoxGroup

box

radio

RadioBoxGroup


toggle_group = pn.widgets.ToggleGroup(name='ToggleGroup', options=['Biology', 'Chemistry', 'Physics'])

toggle_group

Like most other widgets, ToggleGroup has a value parameter that can be accessed or set:

toggle_group.value
[]
toggle_group = pn.widgets.ToggleGroup(name='ToggleGroup', options=['Biology', 'Chemistry', 'Physics'], behavior="radio")

toggle_group

For radio behavior the value is only a single value!

toggle_group.value
'Biology'

The resulting object is not of type ToggleGroup but is an object dependent of the input parameters as shown in the Parameters section

type(toggle_group)
panel.widgets.select.RadioButtonGroup

Controls#

The ToggleGroup widget (concretly the created, underlying widget) exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:

pn.Row(toggle_group.controls(jslink=True), toggle_group)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).