Holoview link_selections error in panel/holoviews/bokeh

reading

https://discourse.holoviz.org/t/how-do-i-link-plots-and-tables/925

https://discourse.holoviz.org/t/selection-fails-when-shared-datasource/1061/2

bokeh=2.02 ,panel=0.9.5, holoviews=‘1.13.5’

i implemented the following code with following errors:-

import pandas as pd
import numpy as np
import holoviews as hv
from holoviews import opts
import panel as pn
import param
from holoviews.selection import link_selections

hv.extension('bokeh')

df = pd.DataFrame(np.random.rand(100,3), columns=['a','b','c'])
dataset = hv.Dataset(df)
link = link_selections.instance()
table = None

def print_sel_indices():
    for i in table.dframe().index:
        print("Dataset index '{i}' is currently selected:".format(i=i))
        print(dataset.iloc[i].data)
        print("-----------------------------------------")

@param.depends(link.param.selection_expr)
def sel_indices_to_table(_):
    global table
    table = hv.Table(dataset.select(link.selection_expr)).opts(width=900, height=200)
    return table

scatter1 = hv.Scatter(data=dataset, kdims=['a', 'b'], vdims=['b'])
scatter2 = hv.Scatter(data=dataset, kdims=['a', 'c'], vdims=['c'])

scat_plots = link(scatter1 + scatter2).cols(2)
scat_plots.opts(shared_axes=True, shared_datasource=False)

layout = pn.Column(scat_plots, sel_indices_to_table)
layout

It Results into following error:-

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
e:\Anaconda\lib\site-packages\IPython\core\formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

e:\Anaconda\lib\site-packages\panel\viewable.py in _repr_mimebundle_(self, include, exclude)
    467 
    468         doc = _Document()
--> 469         model = self._render_model(doc, comm)
    470         ref = model.ref['id']
    471         manager = CommManager(comm_id=comm.id, plot_id=ref)

e:\Anaconda\lib\site-packages\panel\viewable.py in _render_model(self, doc, comm)
    415         if comm is None:
    416             comm = state._comm_manager.get_server_comm()
--> 417         model = self.get_root(doc, comm)
    418 
    419         if config.embed:

e:\Anaconda\lib\site-packages\panel\viewable.py in get_root(self, doc, comm)
    640         """
    641         doc = doc or _curdoc()
--> 642         root = self._get_model(doc, comm=comm)
    643         self._preprocess(root)
    644         ref = root.ref['id']

e:\Anaconda\lib\site-packages\panel\layout.py in _get_model(self, doc, root, parent, comm)
    118         if root is None:
    119             root = model
--> 120         objects = self._get_objects(model, [], doc, root, comm)
    121         props = dict(self._init_properties(), objects=objects)
    122         model.update(**self._process_param_change(props))

e:\Anaconda\lib\site-packages\panel\layout.py in _get_objects(self, model, old_objects, doc, root, comm)
    108             else:
    109                 try:
--> 110                     child = pane._get_model(doc, root, model, comm)
    111                 except RerenderError:
    112                     return self._get_objects(model, current_objects[:i], doc, root, comm)

e:\Anaconda\lib\site-packages\panel\pane\holoviews.py in _get_model(self, doc, root, parent, comm)
    225             plot = self.object
    226         else:
--> 227             plot = self._render(doc, comm, root)
    228 
    229         plot.pane = self

e:\Anaconda\lib\site-packages\panel\pane\holoviews.py in _render(self, doc, comm, root)
    284             kwargs = {}
    285 
--> 286         return renderer.get_plot(self.object, **kwargs)
    287 
    288     def _cleanup(self, root):

e:\Anaconda\lib\site-packages\holoviews\plotting\bokeh\renderer.py in get_plot(self_or_cls, obj, doc, renderer, **kwargs)
     71         combining the bokeh model with another plot.
     72         """
---> 73         plot = super(BokehRenderer, self_or_cls).get_plot(obj, doc, renderer, **kwargs)
     74         if plot.document is None:
     75             plot.document = Document() if self_or_cls.notebook_context else curdoc()

e:\Anaconda\lib\site-packages\holoviews\plotting\renderer.py in get_plot(self_or_cls, obj, doc, renderer, comm, **kwargs)
    238             init_key = tuple(v if d is None else d for v, d in
    239                              zip(plot.keys[0], defaults))
--> 240             plot.update(init_key)
    241         else:
    242             plot = obj

e:\Anaconda\lib\site-packages\holoviews\plotting\plot.py in update(self, key)
    924     def update(self, key):
    925         if len(self) == 1 and ((key == 0) or (key == self.keys[0])) and not self.drawn:
--> 926             return self.initialize_plot()
    927         item = self.__getitem__(key)
    928         self.traverse(lambda x: setattr(x, '_updated', True))

e:\Anaconda\lib\site-packages\holoviews\plotting\bokeh\plot.py in initialize_plot(self, plots, ranges)
    907 
    908                 shared_plots = list(passed_plots) if self.shared_axes else None
--> 909                 subplots = subplot.initialize_plot(ranges=ranges, plots=shared_plots)
    910                 nsubplots = len(subplots)
    911 

e:\Anaconda\lib\site-packages\holoviews\plotting\bokeh\plot.py in initialize_plot(self, ranges, plots)
   1051             else:
   1052                 passed_plots = plots + adjoined_plots
-> 1053                 adjoined_plots.append(subplot.initialize_plot(ranges=ranges, plots=passed_plots))
   1054         self.drawn = True
   1055         if not adjoined_plots: adjoined_plots = [None]

e:\Anaconda\lib\site-packages\holoviews\plotting\bokeh\element.py in initialize_plot(self, ranges, plot, plots)
   2592             isinstance(sp, TablePlot) for sp in self.subplots.values())
   2593         if plot is None and not self.tabs and not self.batched:
-> 2594             plot = self._init_plot(key, element, ranges=ranges, plots=plots)
   2595             self._init_axes(plot)
   2596         self.handles['plot'] = plot

e:\Anaconda\lib\site-packages\holoviews\plotting\bokeh\element.py in _init_plot(self, key, element, plots, ranges)
    576 
    577         if self.toolbar != 'disable':
--> 578             tools = self._init_tools(element)
    579             properties['tools'] = tools
    580             properties['toolbar_location'] = self.toolbar

e:\Anaconda\lib\site-packages\holoviews\plotting\bokeh\element.py in _init_tools(self, element, callbacks)
   2516             el = element.get(key)
   2517             if el is not None:
-> 2518                 el_tools = subplot._init_tools(el, self.callbacks)
   2519                 for tool in el_tools:
   2520                     if isinstance(tool, util.basestring):

e:\Anaconda\lib\site-packages\holoviews\plotting\bokeh\element.py in _init_tools(self, element, callbacks)
    337         # Link the selection properties between tools
    338         if box_tools and lasso_tools:
--> 339             box_tools[0].js_link('mode', lasso_tools[0], 'mode')
    340             lasso_tools[0].js_link('mode', box_tools[0], 'mode')
    341 

e:\Anaconda\lib\site-packages\bokeh\model.py in js_link(self, attr, other, other_attr, attr_selector)
    460         if attr not in self.properties():
    461             raise ValueError("%r is not a property of self (%r)" %
--> 462                              (attr, self))
    463 
    464         if not isinstance(other, Model):

ValueError: 'mode' is not a property of self (BoxSelectTool(id='1009', ...))

Column
    [0] HoloViews(Layout)
    [1] ParamFunction(function)

i also raise the issue with bokeh

[https://discourse.bokeh.org/t/holoview-link-selections-error-in-bokeh-model-py-js-linkjs-link-self-attr-other-other-attr-attr-selector/7118]

you can try the last versions of bokeh, panel and holoviews. It works and there is no error

image

if you change only to one kdims

scatter1 = hv.Scatter(data=dataset, kdims=['a'], vdims=['b'])
scatter2 = hv.Scatter(data=dataset, kdims=['a'], vdims=['c'])

It works and there is no error. It works with the square selections, with the lasso tool not. +

1 Like