Dynamic maps do not appear to respect the hover options for more than the original number of elements. I refer to subsequent (all but the first) invocations of the function which generates the map. Below I have a minimal example where I bind a text input to the argument of the function which generates the map. The example simply plots points at (x,x) where x = offset value, for a list of offsets passed in as a comma separated string.
Start with text = ‘0,1’ and observe points at (0,0) and (1,1) are plotted with working hover. Now try text = ‘0,1,0.5’ and observe an additional point at (0.5,0.5). That third point does not display anything when I hover over it. Why?
Even more strange, try text = ‘0,0.5,1’. Now it works (with the correct information!) for points (0,0) and (0.5,0.5), but I don’t get anything when I hover over point (1,1). It appears that only the first two elements passed to the hv.Overlay respect the hover option, irrespective of when they are added.
Is this a bug? Am I doing it wrong?
import holoviews as hv
from holoviews import opts
import panel as pn
import pandas as pd
import numpy as np
hv.extension('bokeh')
def get_overlay(offsets: str) -> hv.Overlay:
"""Plots a point at (offset,offset) for each offset.
offsets are input as a comma separated list (a string)"""
try:
offsets: list[float] = [float(x.strip()) for x in offsets.split(',')]
except:
offsets: list[float] = [0]
points_list: list[hv.Points] = []
for offset in offsets:
data: np.ndarray = np.array([[0,0,0]]) + offset
data: pd.DataFrame = pd.DataFrame(data,columns=['x','y','z'])
points: hv.Points = hv.Points(data, kdims=['x','y'], vdims=['z'])
points_list.append(points)
# return the overlay, crucially with hover specified
return hv.Overlay(points_list).opts(opts.Points(tools=['hover']))
text_input = pn.widgets.TextInput(name='Enter a comma separated list of offset values',
placeholder='0,1',
value='0,1')
dynamic_map: hv.DynamicMap = hv.DynamicMap(pn.bind(get_overlay, offsets=text_input))
app = pn.Row(text_input, dynamic_map).servable()
app
Package versions (anaconda environment, Windows, Jupyter, VSCode)
holoviews 1.17.1
bokeh 3.2.2
panel 1.2.3
jupyter_bokeh 3.0.7
jupyterlab_widgets 3.0.9