Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed resolving Selection1D in bokeh callback #2586

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict

import param
from bokeh.models import (CustomJS, FactorRange, DatetimeAxis, ColumnDataSource)
from bokeh.models import (CustomJS, FactorRange, DatetimeAxis, ColumnDataSource, Selection)

from ...core import OrderedDict
from ...streams import (Stream, PointerXY, RangeXY, Selection1D, RangeX,
Expand Down Expand Up @@ -355,6 +355,9 @@ def resolve_attr_spec(cls, spec, cb_obj, model=None):
continue
if isinstance(resolved, dict):
resolved = resolved.get(p)
elif isinstance(resolved, Selection) and p in ['1d', 'indices']:
# Handle resolving bokeh Selection 1d indices
resolved = resolved[p]
else:
resolved = getattr(resolved, p, None)
return {'id': model.ref['id'], 'value': resolved}
Expand Down
8 changes: 7 additions & 1 deletion tests/testbokehcallbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from holoviews.plotting.bokeh.util import bokeh_version

from bokeh.events import Tap
from bokeh.models import Range1d, Plot
from bokeh.models import Range1d, Plot, ColumnDataSource, Selection
bokeh_renderer = Store.renderers['bokeh']
except:
bokeh_renderer = None
Expand Down Expand Up @@ -81,6 +81,12 @@ def test_server_callback_resolve_attr_spec_range1d_end(self):
msg = Callback.resolve_attr_spec('x_range.attributes.end', range1d)
self.assertEqual(msg, {'id': range1d.ref['id'], 'value': 10})

def test_server_callback_resolve_attr_spec_source_selected(self):
source = ColumnDataSource()
source.selected = Selection(indices=[1, 2, 3])
msg = Callback.resolve_attr_spec('cb_obj.selected.1d.indices', source)
self.assertEqual(msg, {'id': source.ref['id'], 'value': [1, 2, 3]})

def test_server_callback_resolve_attr_spec_tap_event(self):
plot = Plot()
event = Tap(plot, x=42)
Expand Down