Hey there,
on an attempt to create a responsive plot with two VLine elements, I’ve discovered the option to use streams. Instead of using a method that re-creates the plot and overlays new VLines, every time I change the value for my VLines, I expect streaming to result in better responsiveness. However, while exploring streaming for my use case, I fail to correctly create a hv.DynamicMap
and receive the following error message:
KeyError: "Callable 'ParameterizedMetaclass' accepts more positional arguments than there are kdims and stream parameters"
My minimal code example looks like this:
- I create a
DatetimeRangeSlider
to provide two timestamps - I define two buffers, which are “initialized” with one timestamp each
- For both buffers,
hv.DynamicMap
is used to create aVLine
each and supplied by their respective buffer -
update_VLines
is bound to update the buffer data whenever changes are made to theDatetimeRangeSlider
datetime_range_slider = pn.widgets.DatetimeRangeSlider(
name="Datetime Range Slider",
start=ts_start,
end=ts_end,
value=(ts_start, ts_end),
step=10000,
)
example = pd.DataFrame({'x': []}, columns=['x'])
bufstart = Buffer(example, length=1, index=False)
bufend = Buffer(example, length=1, index=False)
ts_start = pd.Timestamp(year=2000, month=1, day=1)
ts_end = pd.Timestamp(year=2001, month=1, day=1)
bufstart.send(pd.DataFrame([ts_start], columns=['x']))
bufend.send(pd.DataFrame([ts_end], columns=['x']))
start_line = hv.DynamicMap(hv.VLine, streams=[bufstart]).opts(color="red")
end_line = hv.DynamicMap(hv.VLine, streams=[bufend]).opts(color="black")
@pn.depends(datetime_range_slider.param.value, watch=True)
def update_VLines(*args, **kwargs):
bufstart.send(pd.DataFrame([datetime_range_slider.value[0]], columns=['x']))
bufend.send(pd.DataFrame([datetime_range_slider.value[1]], columns=['x']))
pn.Column(
datetime_range_slider,
some_plot * start_line * end_line)