question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tap tool on bokeh server does not select data points with a custom callback

See original GitHub issue

Versions: Firefox 54.0.1 (64-bit) on macOS Sierra, 0.12.6

Expected behavior: With the tap tool, the user can select a data point and the specified callback will fire

Observed behavior: Callback fires intermittently with incorrect parameters, or does not fire at all

mwe.py:

from bokeh import plotting as bplt
from bokeh import layouts as blayouts
from bokeh import models as bmodels
from bokeh import io as bio

fig = bplt.figure(tools="tap")

source = bmodels.ColumnDataSource(dict(x=[0,1], y=[0,1]))

r = fig.circle('x', 'y', source=source, size=4)

def handler(attr, old, new):
    print('attr: {} old: {} new: {}'.format(attr, old, new))

r.data_source.on_change('selected', handler)

bio.curdoc().add_root(blayouts.layout([[fig]]))

bokeh serve --show mwe.py

Steps to reproduce

  1. Run bokeh serve --show mwe.py as above
  2. Click one of the circles
  3. Observe that either i) no output is printed, or ii) the following is printed, indicating the callback fired with incorrect empty arguments:

attr: selected old: {'0d': {'glyph': None, 'indices': []}, '1d': {'indices': []}, '2d': {'indices': {}}} new: {'0d': {'glyph': None, 'get_view': {}, 'indices': []}, '1d': {'indices': []}, '2d': {'indices': {}}}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
p-himikcommented, Aug 1, 2017

I can reproduce on Google Chrome. A couple of things that I notice:

  1. You should increase size - otherwise, it’s way too easy to miss a point
  2. The very first tap on an empty space (so, nothing was and nothing is selected) generates the output in the description - the difference is in get_view. Probably it’s a function that gets added to the selection result dynamically, resulting in this diff
  3. If the very first tap is on a dot, the diff includes both get_view and the correct dot index
  4. In either case, subsequent taps don’t cause the callback to be called if the selection doesn’t change
0reactions
bryevdvcommented, Mar 8, 2019

I updated the code to the current standard usage:

r.data_source.selected.on_change('indices', handler)

and tested on Chrome, FF, and Safari. The circles were a bit hard to hit (because they are tiny) but in every case the callback printed exactly what is expected. There were lots of issues previously with both the “dict” for selections, and also with Bokeh itself replacing whole Selection objects. My guess is this issue was related to those things as well (neither of them exists anymore)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a Bokeh Tap tool to select all points of the ...
Here is an example solution using CustomJS with bokeh 0.12.6. Essentially when the user selects a glyph, you know which row that corresponds ......
Read more >
JavaScript callbacks — Bokeh 2.4.3 Documentation
The HoverTool has a callback which comes with two pieces of built-in data: the index and the geometry . The index is the...
Read more >
Interactive Data Visualization with Bokeh - Trenton McKinney
Bokeh is an interactive data visualization library for Python, and other languages, that targets modern web browsers for presentation.
Read more >
Bokeh: CustomJS and Callbacks - YouTube
In order for a widget to be useful, it needs to be able to perform some action. Using the Bokeh server, it is...
Read more >
Adding Interactions - Bokeh documentation
When used with the Bokeh server, widgets can run arbitrary Python code, ... tools="tap", title="Click the Dots") source = ColumnDataSource(data=dict( x=[1, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found