@param.depends with watch=True not working

Hi,

I’ve got a parameterized class with multiple update functions that are each supposed to trigger whenever the corresponding parameter (as given in the decorator) is changed. (The parameters are all declared as param.ObjectSelectors)
However, even though I put watch=True in the decorators, the functions are not being triggered when the value of the parameter is changed.
Is the depends-decorator somehow broken right now, or am I missing something?

Hi @Yusu.

Could you please provide example code so its possible to test if the problem Can be reproduced. And version of param.

Thanks

Of course. Sorry I didn’t give any coda from the get-go - don’t know why I thought that wasn’t needed.

from bokeh.plotting import figure
import panel as pn
import param
pn.extension()

class Test(param.Parameterized):
    alpha = param.Number(0.6, bounds=(0.1, 1))

    def __init__(self):
        self.p = figure()
        x_values = [1, 2, 3, 4, 5]
        y_values = [6, 7, 2, 3, 6]
        self.circle = self.p.circle(x=x_values, y=y_values, 
                                    fill_alpha=self.alpha, line_color=None,
                                    size=50)
        self.pane = pn.pane.Bokeh(self.p)

    def view(self):
        return pn.Column(self.param, self.pane)

    @param.depends('alpha', watch=True)
    def update(self):
        print("An update happened")
        self.circle.glyph.fill_alpha = self.alpha

pn.Row(Test().view()).show()

The version of param I’m running is 1.9.3

This works fine for me asa long as you call super in the constructor:

import param
pn.extension()

class Test(param.Parameterized):
    alpha = param.Number(0.6, bounds=(0.1, 1))

    def __init__(self):
        super().__init__()
        self.p = figure()
        x_values = [1, 2, 3, 4, 5]
        y_values = [6, 7, 2, 3, 6]
        self.circle = self.p.circle(x=x_values, y=y_values, 
                                    fill_alpha=self.alpha, line_color=None,
                                    size=50)
        self.pane = pn.pane.Bokeh(self.p)

    def view(self):
        return pn.Column(self.param, self.pane)

    @param.depends('alpha', watch=True)
    def update(self):
        print("An update happened")
        self.circle.glyph.fill_alpha = self.alpha

pn.Row(Test().view()).show()

If you also want this to work in a notebook you have to tell the Bokeh pane has happened with .param.trigger:

    @param.depends('alpha', watch=True)
    def update(self):
        print("An update happened")
        self.circle.glyph.fill_alpha = self.alpha
        self.pane.param.trigger('object')
1 Like

Ah, calling super in the constructer did fix it for me as well, thanks!

1 Like