Is there an example of how to use value_throttled?
value_throttled (tuple): Tuple of upper and lower bounds of the selected range throttled until mouseup
I thought up to 5 stops, it would not update unless the mouse was lifted OR it exceeded 6 stops, but it seems to update regardless
text = pn.widgets.StaticText(value="heyyy")
def hey(event):
text.value = "".join(['hey'] * event.new[0])
range_slider = pn.widgets.IntRangeSlider(start=0, end=15, value_throttled=(1, 5))
range_slider.param.watch(hey, "value")
pn.Column(text, range_slider)
Ohhh it’s actually a cousin of “value” e.g.
text = pn.widgets.StaticText(value="heyyy")
def hey(event):
text.value = "".join(['hey'] * event.new[0])
range_slider = pn.widgets.IntRangeSlider(start=0, end=15, value=(1, 5))
range_slider.param.watch(hey, "value")
pn.Column(text, range_slider)
vs
text = pn.widgets.StaticText(value="heyyy")
def hey(event):
text.value = "".join(['hey'] * event.new[0])
range_slider = pn.widgets.IntRangeSlider(start=0, end=15, value_throttled=(1, 5))
range_slider.param.watch(hey, "value_throttled")
pn.Column(text, range_slider)
That’s right, value_throttled
is a readonly parameter that reflects the value
parameter but is throttled on updates so it updates less frequently.
Is it possible to make pn.bind
use value_throttled
instead?
Marc
April 23, 2021, 4:48pm
5
Sure @ahuang11
Like below
import panel as pn
range_slider = pn.widgets.IntRangeSlider(start=0, end=15, value_throttled=(1, 5))
text_input = pn.widgets.TextInput(name="Value")
def update_text_input(value):
text_input.value=str(value)
pn.bind(update_text_input, value=range_slider.param.value_throttled, watch=True)
pn.Column(range_slider, text_input).servable()
You’re AWESOME!
Also thanks a bunch for implementing --autoreload; saves me a lot of time!
1 Like
Oh thanks thanks to Marc for sharing on social media*
Yep, he’s way better at publicizing things than I am. Thanks @Marc !
1 Like
By the way, is there a way to bind multiple widgets with value throttled without separate calls (use case wrapping a DynamicMap around pn.bind.
import panel as pn
pn.extension()
range_slider = pn.widgets.IntRangeSlider(start=0, end=15, value_throttled=(1, 5))
range2_slider = pn.widgets.IntRangeSlider(start=0, end=15, value_throttled=(1, 5))
text_input = pn.widgets.TextInput(name="Value")
def update_text_input(value):
text_input.value=str(value)
pn.bind(update_text_input, value=(range_slider.param.value_throttled, range2_slider.param.value_throttled), watch=True)
pn.Column(range_slider, text_input).servable()
Not sure I’m following completely but won’t this work:
def update_text_input(v1, v2):
text_input.value=str((v1, v2))
pn.bind(update_text_input, v1=range_slider.param.value_throttled, v2=range2_slider.param.value_throttled, watch=True)
I was thinking of something like this, but this doesn’t seem to update
import panel as pn
import holoviews as hv
pn.extension()
xrange_slider = pn.widgets.IntRangeSlider(start=0, end=15, value_throttled=(1, 5))
yrange_slider = pn.widgets.IntRangeSlider(start=0, end=15, value_throttled=(1, 5))
def plot_line(xrange, yrange):
return hv.Curve([0, 1, 2]).opts(xlim=xrange, ylim=yrange)
dmap = hv.DynamicMap(
pn.bind(plot_line, xrange=xrange_slider.param.value_throttled, yrange=yrange_slider.param.value_throttled, watch=True)
)
pn.Column(xrange_slider, yrange_slider, dmap).servable()
Try this:
import panel as pn
import holoviews as hv
pn.extension()
xrange_slider = pn.widgets.IntRangeSlider(start=0, end=15, value_throttled=(1, 5))
yrange_slider = pn.widgets.IntRangeSlider(start=0, end=15, value_throttled=(1, 5))
def plot_line(xrange, yrange):
return hv.Curve([0, 1, 2]).opts(xlim=xrange, ylim=yrange, framewise=True)
dmap = hv.DynamicMap(
pn.bind(plot_line, xrange=xrange_slider.param.value_throttled, yrange=yrange_slider.param.value_throttled)
)
pn.Column(xrange_slider, yrange_slider, dmap).servable()
Use framewise=True
You only have to set watch=True
if the callback works via side-effects (rule-of-thumb if it has a return
do not use watch
)
1 Like
Wow, that’s a great rule of thumb; should this be documented somewhere if not already?
" 1. You only have to set watch=True
if the callback works via side-effects (rule-of-thumb if it has a return
do not use watch
)"
(Even though I used panel since it started, I never understood when to use watch=True until now)
1 Like
I second ahuang11. Although I’ve been using Panel for about a year, I often fumble with the watch=True
kwarg and have to test if my callbacks are executed twice or at all.
3 Likes