holoviz / holoviz/param

Documentation for on_init is incomplete

Open
#586 0 comments 0 reactions 0 assignees View on GitHub
doc
Dominant language
Python
Stars
521
Forks
86
Avg merge
1d 13h
Merged PRs (30d)
35

Description

The `on_init` parameters to @depends is supposed to be documented in the [Dependencies and Watchers](https://github.com/holoviz/param/blob/master/examples/user_guide/Dependencies_and_Watchers.ipynb) 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:

```python
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:

```python
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]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.