param
param copied to clipboard
Documentation for on_init is incomplete
The on_init parameters to @depends is supposed to be documented in the Dependencies and Watchers notebook on the user guide.
However, while the markdown mentions setting on_init=True instead of manually declaring ´objects´ and ´default´, the actual code does not actually figure on_init=True.
I am assuming this code:
class C(param.Parameterized):
_countries = {'Africa': ['Ghana', 'Togo', 'South Africa'],
'Asia' : ['China', 'Thailand', 'Japan', 'Singapore'],
'Europe': ['Austria', 'Bulgaria', 'Greece', 'Switzerland']}
continent = param.Selector(list(_countries.keys()), default='Asia')
country = param.Selector(_countries['Asia'])
@param.depends('continent', watch=True)
def _update_countries(self):
countries = self._countries[self.continent]
self.param['country'].objects = countries
if self.country not in countries:
self.country = countries[0]
should actually be:
class C(param.Parameterized):
_countries = {'Africa': ['Ghana', 'Togo', 'South Africa'],
'Asia' : ['China', 'Thailand', 'Japan', 'Singapore'],
'Europe': ['Austria', 'Bulgaria', 'Greece', 'Switzerland']}
continent = param.Selector(list(_countries.keys()), default='Asia')
country = param.Selector() # Nothing declared here
@param.depends('continent', watch=True, on_init=True) # Add on_init = True here
def _update_countries(self):
countries = self._countries[self.continent]
self.param['country'].objects = countries
if self.country not in countries:
self.country = countries[0]