Can you "discard_events" but still update the GUI?

I occasionally want to update a parameter without triggering the methods that depend on it. However, I still want the parameter widget in the GUI to update.

Here is a simple example:

class Demo(param.Parameterized):
    a = param.Number(default=4)
    
    @param.depends('a', watch=True)
    def a_trigger(self):
        print('a was triggered')
        
    def panel(self):
        return pn.Column(
            self.param.a,
        )
    
d = Demo()
d.panel()

panel_events

In the first cell the method with the print statement is triggered, and the widget value updates.

In the second cell the method is not triggered nor is the widget updated.

Is there some way to not trigger the method, but still update the widget value?

1 Like

you could do

d = Demo()
gui = d.panel()
print( gui )              # lets look at the widgets
gui

and set the parameter explicitely:

with param.discard_events(d):
    d.a              = 10
    gui[0].value = 10

There may be a better solution!

1 Like