Set a watched value without triggering event?

Hi,

Is there a way that I can set a value of a watched object and not trigger its callback? Or some clever way to not run the callback event for that specific one.

This described my situation:

my_btn = pn.widgets.Button(...)
my_btn.on_click(my_click)

self.date_selector.param.watch(self.set_page, "value")
self.view.param.watch(self.set_page, "value")

def my_click(self, _event=None):
    """Set selected date to today's date"""
    self.view.value ="MONTHLY"
    self.date_selector.value = date. Today()

def set_page(_event=None)
    """ CODE TO SET UP THE MAIN CONTENT"

e.g. here the my_btn needs to do two things, set the view to MONTHLY and set the date to today. But both are watched and trigger the same function. So it will run twice.

The only workaround I can think of is to remove my watcher for self.view, change the value, reinstate the watcher and continue.

You should be able to use the param.discard_events context manager.

1 Like