3

Cant find a working example of using Radio button group ( Adding Interaction ). In the documentation there is an example how to create the group, but how can I use it?

For example how can I create a figure with 2 radio button so if i click the one a plot is showed and if i click the other another plot is showed.

Mpizos Dimitris
  • 4,819
  • 12
  • 58
  • 100
  • If you solved this one, could you post your own answer? I would like to see how you were able to do it. – KobeJohn Mar 12 '16 at 16:52
  • @KobeJohn Im sorry,I wasn't able to solve it. I used the tab panes for my task. – Mpizos Dimitris Mar 12 '16 at 21:32
  • I believe, [mosc9575](https://stackoverflow.com/questions/69462392/hide-several-lines-using-checkboxes-and-customjs-in-python-bokeh) solved the proposed example of turning plots on and off in another post using *CheckboxGroup*. – Shudras Feb 04 '23 at 09:45

1 Answers1

6

Define the group:

from bokeh.models.widgets import RadioButtonGroup
radio_button_group = RadioButtonGroup(labels=['Plot1', 'Plot2'], active=0)

Use the following line if you want to act immediately when the radio button is pressed:

radio_button_group.on_change('active', lambda attr, old, new: update())

The active choice can be accessed in your update() function under:

radio_button_group.active

Note the values are enumerated: 0 for 'Plot1' and 1 for 'Plot2'

MOF
  • 61
  • 1
  • 3