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

@philippjfr I just ran into this issue again, and I remember discussing, at some point, a possible solution like having precedence argument to control when params are triggered. I thought there was an issue for it, but I can’t seem to find it now. Do you remember if we documented that anywhere?

Edit: I got more creative with my searching and was able to find the issue:

I filed the issue with Panel, but perhaps Param would be a better place for it.