How to use callback policy intrange slider?

Hello,
I have somehow big comuptation with an intrangeslider I want to start the calculation after a mouseup.

It doesnot seems to work. Can anyone show me an exemple ?

https://panel.holoviz.org/reference/widgets/IntRangeSlider.html

1 Like

The documentation is out of date, the documentation will be updated at the next Panel update. You can find the lastest here: https://github.com/holoviz/panel/blob/master/examples/reference/widgets/IntRangeSlider.ipynb

But in short callback_throttle is deprecated use value_throttled instead of.

Thanks for your answer.

I don’t get it. I am using a parametrized class.

class A(param.Parameterized):
    score = param.Range(
        default=(0, 250),
        bounds=(0, 250),
    )

@pn.depends(??)
def calculation(self):

I don’t know which value to look at ?

Try something like this. I feel like this is a bit of a hack, so maybe there is a better way.

import param
import panel as pn
pn.extension()

class A(param.Parameterized):
    score = param.Range(
        default=(0, 250),
        bounds=(0, 250),
    )
    
    def __init__(self, **params):
        super().__init__(**params)
        self.controls = pn.Param(self, widgets={
            "score": {"type": pn.widgets.IntRangeSlider},
        })
        self.score_widget = self.controls[1]

    @param.depends("score_widget.value_throttled")
    def calculation(self):
        return self.score

a = A()
pn.Column(a.score_widget, a.calculation)
3 Likes

It’s a bit of hack but seems to work. :slight_smile:
I like to structure with class, but unfortunately, sometimes we need to do this kind of hack.

I change @param.depends to @pn.depends

If there is a better solution without an extra parameter, I take it !

This actually not working. I reimplemented it using another widget and score gets desynchronized from the widget.
Just drag this slider few times and you will see.

class A(param.Parameterized):
    score = param.Integer(
        default=5,
        bounds=(0, 250),
    )
    
    blank = hv.Points([(1,1)]).opts(xlim=(-1,251),alpha=0)
    
    def __init__(self, **params):
        super().__init__(**params)
        self.controls = pn.Param(self, widgets={
            "score": {"type": pn.widgets.IntSlider},
        })
        self.score_widget = self.controls[1]

    @param.depends("score_widget.value_throttled")
    def calculation(self):
        return self.blank*hv.VLine(self.score)*hv.Text(x=self.score,y=1.5,text=str(self.score))

a = A()
pn.Column(a.score_widget, a.calculation)

Here is what I see on my side (attached video).

Which version are you running? I can see I have the same problem as you when I run version 0.10.1, but when I run the latest development version it seems to work fine. You can install the latest development version with conda install panel -c pyviz/label/dev. Can you check if this is the same case for you?

1 Like

I didn’t notice any issue. I am in developpment mode too.

1 Like

Great to know that it is fixed in that version - I’ll check if I can install it. Thank you!

In meanwhile, since you are not using param's magic - wouldn’t it be easier to simple use basic class instead.
It’s actually exactly what I did (using pure widget only implementation)

To be honest, I wish there would be a simple flag in widgets/param/interact to make things throttle similarly to continuous_updates in ipywidgets. This would safe (at least) 3 lines of code per widget/param.

1 Like

To be honest, I wish there would be a simple flag in widgets/param/interact to make things throttle similarly to continuous_updates in ipywidgets. This would safe (at least) 3 lines of code per widget/param.

Me too, see #1754.

1 Like