I would like to use IntRangeSlider
to pick a integer range (start, end). How do I make it interactive?
I tried this:
import hvplot.pandas
import pandas as pd
import numpy as np
import panel as pn
pn.extension(sizing_mode="stretch_width", template="fast")
data1 = pn.rx(pd.DataFrame(dict(a=np.random.randn(100), b=np.random.randn(100))))
data2 = pn.rx(pd.DataFrame(dict(a=np.random.randn(100), b=np.random.randn(100))))
slider = pn.widgets.IntRangeSlider(
name="rande for b",
start=0,
end=100,
value=(0, 100),
step=10,
).servable(area="sidebar")
data1 = data1[data1["b"].between(slider.value[0], slider.value[1])]["a"]
data2 = data2[data2["b"].between(slider.value[0], slider.value[1])]["a"]
combined_scatter = data1.hvplot.scatter() * data2.hvplot.scatter()
combined_plot = pn.ReactiveExpr(combined_scatter)
combined_plot.servable(title="My Title")
But it is not interactive. The slider.value
seems to be constant, just like the docs day. Namely, the docs say:
text = pn.widgets.TextInput()
text.value # π the "value" Parameter of this widget reflects the current value
text.param.value # π can be used as a reference to the live value
But if I try to use the slider.param.value
, it wonβt also work as the Range
object the slider.param.value
is not subscriptable.
TypeError: 'Range' object is not subscriptable
This must be a simple thing. How do you use the IntRangeSlider
widget with ReactiveExpr?