Hi,
When I decorate a method in a Parameterized class with @param.depends
I can watch nested parameters (as described here), e.g. @param.depends("something.sub", watch=True)
.
How can I do the same using param.watch()
? Because param.watch(my_func, ["something.sub"])
doesn’t work.
Thanks,
Bert
Figured it out myself:
import param
class Something(param.Parameterized):
n = param.Number(default = 2)
def __init__(self, **params):
super().__init__(**params)
class App(param.Parameterized):
x = param.ClassSelector(class_ = Something)
def __init__(self, **params):
super().__init__(**params)
self.x = Something()
self.x.param.watch(self.test, ["n"])
# @param.depends("x.n", watch=True)
def test(self, event):
print(f"n {event.type} from {event.old} to {event.new}")
app = App()
app.x.n = 5
>>> n changed from 2 to 5