Hi,
Please have a look at the below structure.
@pn.depends is invoked multiple times when used in the same class and also when inherited.
If the p1 widget in widgetOne.py is updated, then the dependent function (def check(self) ) is invoked twice. When the same class (MyClassOne) is inherited to another class (i.e MyClassTwo of widgetTwo.py) the behavior is the same. Can anyone let me know why the function is invoked twice ??
Please have a look at my previous issue while inheriting parameters, where the function itself is not invoked in the inherited class. Is the structure wrong ?? (Usage of param Parameters in different classes)
Thanks in advanceā¦!!
base.py
import panel as pn
import holoviews as hv
from widgetOne import MyClassOne
from widgetTwo import MyClassTwo
class myClass:
def __init__(self):
pn.extension()
hv.extension('bokeh')
classOneObj = MyClassOne()
classTwoObj = MyClassTwo()
base = pn.template.FastListTemplate(site="Param Library",
title="Learning Param",
accent_base_color="#4099da",
theme_toggle=False,
busy_indicator=None
)
base.main.extend([
pn.Row(pn.Card(classOneObj.p1,
title = "Card One",
sizing_mode= 'stretch_width',
background='lightgrey'),
pn.Card(classTwoObj.p2,
title = 'Card Two',
sizing_mode = 'stretch_width',
background='lightgrey')
)
])
base.servable()
myClassObj = myClass()
widgetOne.py
import panel as pn
class MyClassOne(param.Parameterized):
p1 = pn.widgets.TextInput(name="Input",placholder = "Enter input value")
@pn.depends('p1.value', watch=True)
def check(self):
print("In MyClassOne paramOne updated...,", self.p1.value)
widgetTwo.py
import panel as pn
from widgetOne import MyClassOne
class MyClassTwo(MyClassOne):
p2 = pn.widgets.TextInput(name="Input-Two",placholder = "Enter input value")
@pn.depends('p2.value','p1.value',watch=True)
def check(self):
print("In myClassTwo, paramOne updated...",self.p1.value, self.p2.value)
> panel serve base.py --autoreload --show