Panel: 'mouseup' slider widget update policy not working with `@panel.depends`

Created on 1 Aug 2019  路  3Comments  路  Source: holoviz/panel

As per the answer to my SO question earlier, it seems like the value_throttled attribute is not defined correctly for param.widgets.IntSlider.

The following code updates the value continuously instead of at mouseup:

import panel as pn


pn.extension()
int_slider = pn.widgets.IntSlider(name='Integer Slider', end=5, callback_policy='mouseup')

@pn.depends(int_slider.param.value, watch=True)
def print_slider_value(slider_value):
    return slider_value

pn.Column(int_slider, print_slider_value)#.app('localhost:8888')

Creating a subclass with value_throttled works as expected and updates only when releasing the mouse button:

import param

class IntThrottledSlider(pn.widgets.IntSlider):
    value_throttled = param.Integer(default=0)

int_slider = IntThrottledSlider(
    name='Integer Slider', end=5, callback_policy='mouseup')

@pn.depends(int_slider.param.value_throttled, watch=True)
def print_slider_value(slider_value):
    return slider_value

pn.Column(int_slider, print_slider_value)

I also tested with param.widgets.Floatslider and the behavior is the same.

Package versions:

bokeh       1.2.0
panel       0.6.0
IPython     6.5.0
jupyter_client  5.2.3
jupyter_core    4.4.0
jupyterlab  1.0.2
notebook    5.6.0
bug

Most helpful comment

Thanks @Hoxbro, I think callback_policy was broken for a long time and has now been deprecated. I'll simply switch to value_throttled if callback_policy='throttled'/'mouseup'.

All 3 comments

This seems to also be the case for pn.widgets.DateRangeSlider, but can be corrected with the procedure mentioned above + updating the _process_property_change function, like shown below:

class DateRangeSliderThrottled(pn.widgets.DateRangeSlider):
    value_throttled = param.Tuple(default=(None, None), length=2)

    def _process_property_change(self, msg):
        msg = super(DateRangeSliderThrottled, self)._process_property_change(msg)
        if 'value' in msg:
            v1, v2 = msg['value']
            msg['value'] = (value_as_datetime(v1), value_as_datetime(v2))
        if 'value_throttled' in msg:
            v1, v2 = msg['value_throttled']
            msg['value_throttled'] = (value_as_datetime(v1), value_as_datetime(v2))
        return msg

I have attached an example.

Thanks @Hoxbro, I think callback_policy was broken for a long time and has now been deprecated. I'll simply switch to value_throttled if callback_policy='throttled'/'mouseup'.

Great! Thanks for fixing this!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MarcSkovMadsen picture MarcSkovMadsen  路  5Comments

maximlt picture maximlt  路  4Comments

MarcSkovMadsen picture MarcSkovMadsen  路  4Comments

MarcSkovMadsen picture MarcSkovMadsen  路  3Comments

kcpevey picture kcpevey  路  4Comments