I have a Select widget that should give a different list of options whenever another Select widget is changed, so it updates whenever this other Select widget changes. How do I this in the example code below?
_countries = {
'Africa': ['Ghana', 'Togo', 'South Africa'],
'Asia' : ['China', 'Thailand', 'Japan'],
'Europe': ['Austria', 'Bulgaria', 'Greece']
}
continent = pn.widgets.Select(
value='Asia',
options=['Africa', 'Asia', 'Europe']
)
country = pn.widgets.Select(
value=_countries[continent.value][0],
options=_countries[continent.value]
)
@pn.depends(continent.param.value)
def _update_countries(continent):
countries = _countries[continent]
country.options = countries
country.value = countries[0]
pn.Row(continent, country)
So, it took me forever to find this out, but in your @pn.depends() you have to add argument watch=True, so it constantly listens if changes are happening and updates to your other list should be done.
In this case:
Whole example:
The example of the GoogleMapViewer on this page pointed me in the right direction:
Selector updates after another selector is changed
The same answer but then in the form of a Class: