Updating options in a widget by a previous widget value

I want to make a dashboard with two selector widgets (like the image below). But the options in the second widget will depend on the value of the first widget. So if ou change the first button value, the second button has to update the values option.

I was trying to use class method in Param but cannot find examples to help me in the websites

Thanks

image

Here is a simple example expressing a hierarchical dependency in param:

class Countries(param.Parameterized):
    
    _hierarchy = {
        'Europe': ['Germany', 'Denmark', 'Sweden'],
        'Asia': ['Japan', 'South Korea', 'China']
    }

    continent = param.Selector(default='Asia', objects=['Europe', 'Asia'])
    
    country = param.Selector(default='Japan', objects=_hierarchy['Asia'])
    
    @pn.depends('continent', watch=True)
    def _update_countries(self):
        countries = self._hierarchy[self.continent]
        self.param.country.objects = countries
        self.country = countries[0]

pn.panel(Countries())

Hope that helps.

1 Like