link_selections does not work on complex Dynamic Map
See original GitHub issueIs your feature request related to a problem? Please describe.
hv.selection.link_selections
does not work on complex DynamicMap
s. For example, the following code:
from collections import OrderedDict
import numpy as np
import holoviews as hv
import panel as pn
hv.extension('bokeh')
# Widgets
x_offset_slider = pn.widgets.FloatSlider(
name='x-offset',
start=-5, end=5, step=0.1, value=0.
)
y_offset_slider = pn.widgets.FloatSlider(
name='y-offset',
start=-5, end=5, step=0.1, value=0.
)
widget_box = pn.WidgetBox(
x_offset_slider,
y_offset_slider
)
@pn.depends(
x_offset=x_offset_slider,
y_offset=y_offset_slider,
)
def gen_points_overlay(x_offset, y_offset):
points_dct = OrderedDict([
('p1', hv.Points(np.random.randn(1000, 2), kdims=['x', 'y'], label='p1')),
('p2', hv.Points(np.random.randn(1000, 2) + np.array([x_offset, y_offset]), kdims=['x', 'y'], label='p2'))
])
return hv.NdOverlay(points_dct, kdims=['cat'])
dmap_2d = hv.DynamicMap(
gen_points_overlay, kdims=['x_offset', 'y_offset']
).opts(
hv.opts.Points(framewise=True)
)
dmap_hist = dmap_2d.map(map_fn=lambda p: hv.operation.histogram(p, dimension='x'), specs=hv.Points)
linked_plot = hv.selection.link_selections(dmap_2d + dmap_hist)
app = pn.Column(linked_plot, widget_box)
app
Results in: Notice the absence of the selection tools.
After some debugging I think the underlying issue is that link_selections
creates a new DynamicMap
. However, somehow the original and selection DynamicMaps are not correctly combined, and I think it’s because this (which should probably raise a warning?): https://github.com/holoviz/holoviews/blob/effaf45f9c2e7bf33c9f7ee830c2aa355badaae2/holoviews/selection.py#L180-L182
If I understand everything correctly, it seems like it is currently impossible to combine link_selections
with a DynamicMap
from a custom function. However, I’m wondering if there is a workaround by embedding the selection directly into the custom function? Would anyone be able to help me find a workaround?
Describe the solution you’d like
Support for hv.selection.link_selections
on complex DynamicMap
s.
Describe alternatives you’ve considered
Extending DynamicMap.map()
to add new streams so I can manually add a new selection stream on top of the existing DynamicMap
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
warning added in https://github.com/holoviz/holoviews/pull/5044 to make clear that
link_selections
does not work on complex Dynamic Map.I’m willing to have a look to see if I can cover more cases, and the above case more specifically, if anyone has some suggestions on how to cover these.