How to trigger param.depends only once when updating multiple parameters


I have a parameterized class with multiple parameters and one function that depends on a lot of these.

Sometimes I would like update multiple of these due to a change of “theme”. The problem is I have a function when depends on each of these parameters. And I only want it to run once for efficiency reasons.

What is the best way to achieve that?

Can I deactive the watchers while updating and then manually run the function when done? How?


In the example below the dependent function is the _inc function. I want to be able to update both param1 and param2.

The actions in “red” are not working for me as they _inc twice.
The action in “green” is working for me as it runs _inc once.

But is it best practice?

import param
import panel as pn

class MultiParamApp(param.Parameterized):
    count = param.Integer(0)
    param1 = param.Integer(0)
    param2= param.Integer(0)
    update = param.Action()
    update_once = param.Action()
    update_once_disable_watchers = param.Action()
    reset = param.Action()

    view = param.Parameter()

    def __init__(self, **params):

        self._updating = False

        self.update = self._update
        self.update_once = self._update_once
        self.update_once_disable_watchers = self._update_once_disable_watchers
        self.reset = self._reset

        self.view = pn.Param(self,
            widgets = {
                "update": {"button_type": "danger"},
                "update_once": {"button_type": "danger"},
                "update_once_disable_watchers": {"button_type": "success"},

    @param.depends("param1", "param2", watch=True)
    def _inc(self):
        if not self._updating:
            self.count += 1

    def _update(self, _=None):
        self.param1 = self.param1 +1
        self.param2 = self.param2 +1

    def _update_once(self, _=None):
        self.param.set_param(param1= self.param1+1, param2= self.param2+1)

    def _update_once_disable_watchers(self, _=None):
        self._updating = True
        self._updating = False

    def _reset(self, _=None):
        self.count = 0


This one should definitely be working and if it isn’t that’s a real param bug that should be reported.

The _update_once() indeed unexpectedly runs _inc() twice.
Any update on this? Is it a bug?

1 Like

Hi @mcav

Only news I know of is that there is an issue on Github and it has been confirmed as a bug.