I think the title describes the question - It is not clear why param.depends is actually needed in a parameterized class.
For instance, I can comment @param.depends('phase', 'frequency') out completely in this simple example from the docs, and the plot is still reactive to changes in the widgets.
import numpy as np
class Sine(param.Parameterized):
phase = param.Number(default=0, bounds=(0, np.pi))
frequency = param.Number(default=1, bounds=(0.1, 2))
@param.depends('phase', 'frequency') # This is entirely unnecessary for the app to function
def view(self):
y = np.sin(np.linspace(0, np.pi * 3, 40) * self.frequency + self.phase)
y = ((y - y.min()) / y.ptp()) * 20
array = np.array(
[list((' ' * (int(round(d)) - 1) + '*').ljust(20)) for d in y])
return pn.pane.Str('\n'.join([''.join(r) for r in array.T]), height=380, width=500)
sine = Sine(name='ASCII Sine Wave')
pn.Row(sine.param, sine.view)
From what I understood in the example is that it makes a HUGE difference whether sine.view is passed to the pn.Row or if sine.view() is passed. In the second case the dependencies are not automatically figured out, and things only depends on what the coder specified.
That’s correct. The purpose of @param.depends is to declare that the given method depends only on a subset of the parameters. Without any explicit decoration limiting such dependencies, all you know is that every method could depend on any parameter. Presumably with code introspection we could automatically deduce which methods depend on which parameters, but we try not to rely on magic like that, so instead we make the conservative assumption that any change to a parameter could make the output of that method be stale and thus need updating. In practice I’d recommend always declaring the dependencies explicitly for a viewable method so that humans know you meant to depend on those parameters and so that your function won’t be called unnecessarily for unrelated parameter changes.