Is there a way to update value_throttled in slider through code/programmatically?

I’m using the value_throttled attribute of pn.widgets.RangeSlider() for callbacks in my app and it’s great for my heavy calculation updates: it waits until the button release to trigger the update. However I can’t set any value for value_throttled programmatically, which I would really appreciate as I’d like a reset button to reset all my sliders.

Setting it directly is not allowed myslider.value_throttled = 5 gives me a:

TypeError: Constant parameter ‘value_throttled’ cannot be modified

But updating the myslider.value = 5 leaves the value_throttled untouched, see gif below.

How can I use value_throttled and still update the value through code?

slider_value_throttled_not_updated

I think the Intentions of value_throttled is to only be used in pn.depends, pn.bind or pn.interact to delay the action of the slider until the release of the mouse and then use actual value inside the function.

For the reset you could properly set the value back to default and call the function which depends on the value_throttled. If this is not possible (by design of your app) there is a way to change value_throttled itself, but this can leave to bad side effects.

Thanks for your quick reply. Using the .value instead works!
For the reset button, I now update the value attribute, which resets the sliders and call my callback function explicitly. This is actually an improvement, as the callback isn’t triggered every time I reset a single slider!

1 Like

I’m have a similar issue, but when trying to tie a param.Parameter to a widget with value_throttled:

import param
import panel as pn

class Test(param.Parameterized):
    value = param.Integer()
  
    @param.depends('value', watch=True)
    def expensive_operation_with_value(self):
        pass

    def panel(self):
        return pn.Param(self, widgets={'value': {'type': pn.widgets.IntSlider, 'throttled': True}})
    
t = Test()
t.panel()
t.value = 4

This will result in the same error:

TypeError: Constant parameter 'value_throttled' cannot be modified

@philippjfr is this a use case that should be supported? Or should I look for an alternative route? like directly creating the widget and using pn.depends instead of trying to tie it to a parameter.

1 Like

To be honest I would use pn.extension(throttled=True).