Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
holoviz
GitHub Repository: holoviz/panel
Path: blob/main/examples/reference/widgets/RadioButtonGroup.ipynb
2011 views
Kernel: Unknown Kernel
import panel as pn pn.extension()

The RadioButtonGroup widget allows selecting from a list or dictionary of values using a set of toggle buttons. It falls into the broad category of single-value, option-selection widgets that provide a compatible API and include the RadioBoxGroup, Select, and DiscreteSlider widgets.

Discover more on using widgets to add interactivity to your applications in the how-to guides on interactivity. Alternatively, learn how to set up callbacks and (JS-)links between parameters or how to use them as part of declarative UIs with Param.

Parameters:

For details on other options for customizing the component see the layout and styling how-to guides.

Core
  • options (list or dict): A list or dictionary of options to select from

  • value (object): The current value; must be one of the option values

Display
  • button_style (str): The button style, either 'solid' or 'outline'.

  • button_type (str): A button theme should be one of 'default' (white), 'primary' (blue), 'success' (green), 'info' (yellow), or 'danger' (red)

  • description (str | Bokeh Tooltip | pn.widgets.TooltipIcon): A description which is shown when the widget is hovered.

  • disabled (boolean): Whether the widget is editable

  • name (str): The title of the widget

  • orientation (str, default='horizontal'): Button group orientation, either 'horizontal' or 'vertical'.


radio_group = pn.widgets.RadioButtonGroup( name='Radio Button Group', options=['Biology', 'Chemistry', 'Physics'], button_type='success') radio_group

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

radio_group.value

Styles

The color of the buttons can be set by selecting one of the available button_type values and the button_style can be 'solid' or 'outline':

pn.Row( *(pn.Column(*( pn.widgets.RadioButtonGroup( name=p, button_type=p, button_style=bs, options=['Foo', 'Bar', 'Baz'], value='Bar' ) for p in pn.widgets.Button.param.button_type.objects )) for bs in pn.widgets.Button.param.button_style.objects) )

Controls

The RadioButtonGroup 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(radio_group.controls(jslink=True), radio_group)