link two Select widgets

Hi, a total novice to Bokeh here. I would really appreciate some help on something that may be quite trivial.

I am trying to get inputs from two Select menus, first one is years and for each selected year, the second menu should get updated with a list of storms. I am not sure how to achieve this. I tried the following:

options_data = {‘1991’:[‘a’,‘b’,‘c’], ‘1992’:[‘x’,‘y’,‘z’]}
selected_year = ‘1991’
selected_storm = ‘All’

year_select = bokeh_models.Select(value=selected_year, title=‘Year:’,
options=options_data.keys())
storm_select = bokeh_models.Select(value=selected_storm, title=‘Storm:’,
options=options_data[selected_year])

I’m sure the following is rubbish!

def update_storm_names(attrname, old, new):
# Get the current slider values
storm_select = bokeh_models.Select(value=selected_storm, title=‘Storm:’,
options=options_data[year_select.value])

year_select.on_change(‘value’, update_storm_names)

``

Any suggestions are most welcome!

Thanks,

PX

You can update the options themselves in the callback, in your code you are making a new widget each time

storm_select.options = [list,of,options]

``

···

Le lundi 22 janvier 2018 18:37:12 UTC-5, Prince Xavier a écrit :

Hi, a total novice to Bokeh here. I would really appreciate some help on something that may be quite trivial.

I am trying to get inputs from two Select menus, first one is years and for each selected year, the second menu should get updated with a list of storms. I am not sure how to achieve this. I tried the following:

options_data = {‘1991’:[‘a’,‘b’,‘c’], ‘1992’:[‘x’,‘y’,‘z’]}
selected_year = ‘1991’
selected_storm = ‘All’

year_select = bokeh_models.Select(value=selected_year, title=‘Year:’,
options=options_data.keys())
storm_select = bokeh_models.Select(value=selected_storm, title=‘Storm:’,
options=options_data[selected_year])

I’m sure the following is rubbish!

def update_storm_names(attrname, old, new):
# Get the current slider values
storm_select = bokeh_models.Select(value=selected_storm, title=‘Storm:’,
options=options_data[year_select.value])

year_select.on_change(‘value’, update_storm_names)

``

Any suggestions are most welcome!

Thanks,

PX