Skip to content

Documentation for on_init is incomplete #586

Description

@dnabb

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    docdocs, interactive help, auto-completion, etc

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions