Env: bokeh 1.4.0, panel 0.8.0, param 1.9.3
This is the code I’m running:
import param
import panel as pn
class Dummy(param.Parameterized):
l = param.Number(default=10, bounds=(2,50), step=1)
x = param.Number(default=2*l.default, bounds=(2, None), step=1)
@param.depends("l", watch=True)
def update_x(self):
print("update_x")
self.x = 2 * self.l
def view(self):
print("view")
return self.x
dummy = Dummy()
app = pn.Row(dummy.param.l, dummy.view)
app.servable()
I get this in the standard output when I move the slider twice:
update_x
view
view
update_x
view
view
The view
method, which in the app
object appears as a ParamMethod
object, gets called twice.
FYI, I found a very useful dashboard example on example.pyviz.org (here) that explains how to set up a panel output with dynamic behaviour, I’m trying to understand how the 4 described methods work.
What I’m trying to do is close to Method 1 (Method dependency for Panel). To get it as described, I need to add a @param.depends("paramname")
on the view
method, such as:
import param
import panel as pn
class Dummy(param.Parameterized):
l = param.Number(default=10, bounds=(2,50), step=1)
x = param.Number(default=2*l.default, bounds=(2, None), step=1)
@param.depends("l", watch=True)
def update_x(self):
print("update_x")
self.x = 2 * self.l
@param.depends("x")
def view(self):
print("view")
return self.x
dummy = Dummy()
app = pn.Row(dummy.param.l, dummy.view)
app.servable()
This works better:
update_x
view
update_x
view
But I would be interested to understand why the first test “failed” (view
being called twice in a row). It was not obvious that it was not working 100% because the x
value was being updated and displayed correctly.
Thanks for your help