I’m seeing unexpected behavior when trying to update a widget from its own callback on a model built on param.Parameterized. In the following example, using classic panel widgets works as expected. The checkbox resets itself to False every time it is clicked. However, when building a parameterized model with param.depends decorators, the widget is not updated. It looks like the underlying model is updating correctly, but it is not being reflected in html.
Any help or suggestions would be much appreciated ![]()
# python 3.12.10, panel 1.7.5, param 2.2.1
import panel as pn
import param
pn.extension()
# Works as expected:
# Classic panel widget checkbox with bound function that sets itself to False
widget_checkbox = pn.widgets.Checkbox(name='Widget checkbox')
@pn.depends(widget_checkbox, watch=True)
def update_checkbox(event):
widget_checkbox.value = False
print(f'Widget checkbox value set to {widget_checkbox.value}')
# Does not work as expected:
# Parameterized model with boolean value parameter
class ParameterizedCheckbox(param.Parameterized):
value = param.Boolean(label='Parameterized checkbox')
@param.depends('value', watch=True)
def update(self):
self.value = False
print(f'ParameterizedCheckbox value set to {self.value}')
pn.Column(
'Both of these checkboxes should uncheck themselves after being clicked.',
widget_checkbox,
ParameterizedCheckbox().param.value
).servable()
Note that there is potential for infinite recursion here if the widget value changes every callback. However, it is avoided in this example because after the second callback the value is unchanged, so no more callbacks are triggered. A more complete app could have recursion blocking logic to prevent this.