Can't trigger python callback for mouse event

I am trying to get the mouse coordinates when a user taps on a given plot. I am using bokeh.client and pushing curdoc() and also using session.loop_until_closed()

I can get the code to run when I used bokeh serve --show events.py, but when I start a bokeh server and execute the script in an IDE, I am unable to print the coordinates.

The code I have so far is shown below:

import numpy as np

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh import events
from bokeh.models import CustomJS, Div, Button
from bokeh.layouts import column, row
from bokeh.client import push_session

def print_event(attributes=[]):
    """
    Function that returns a Python callback to pretty print the events.
    """
    def python_callback(event):
        for attr in attributes:
            print(event.__dict__[attr])
    return python_callback

# Follows the color_scatter gallery example

N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = [
    "#%02x%02x%02x" % (int(r), int(g), 150) for r, g in zip(50+2*x, 30+2*y)
]

p = figure(tools="pan,wheel_zoom,zoom_in,zoom_out,reset")

p.scatter(x, y, radius=radii,
          fill_color=colors, fill_alpha=0.6,
          line_color=None)

layout = column(p)

point_attributes = ['x', 'y']

# Point events

p.on_event(events.Tap, print_event(attributes=point_attributes))
p.on_event(events.DoubleTap, print_event(attributes=point_attributes))

curdoc().add_root(layout)

session = push_session(curdoc())

session.show()
session.loop_until_closed()

To date, upport for events has only been added to apps running in the server. They do not yet function with bokeh.client usage. See:

  https://github.com/bokeh/bokeh/issues/6092

For more information.

Thanks,

Bryan

···

On Jul 13, 2017, at 12:23, [email protected] wrote:

I am trying to get the mouse coordinates when a user taps on a given plot. I am using bokeh.client and pushing curdoc() and also using session.loop_until_closed()

I can get the code to run when I used bokeh serve --show events.py, but when I start a bokeh server and execute the script in an IDE, I am unable to print the coordinates.

The code I have so far is shown below:
import numpy as np

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh import events
from bokeh.models import CustomJS, Div, Button
from bokeh.layouts import column, row
from bokeh.client import push_session

def print_event(attributes=):
    """
    Function that returns a Python callback to pretty print the events.
    """
    def python_callback(event):
        for attr in attributes:
            print(event.__dict__[attr])
    return python_callback

# Follows the color_scatter gallery example

N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = [
    "#%02x%02x%02x" % (int(r), int(g), 150) for r, g in zip(50+2*x, 30+2*y)
]

p = figure(tools="pan,wheel_zoom,zoom_in,zoom_out,reset")

p.scatter(x, y, radius=radii,
          fill_color=colors, fill_alpha=0.6,
          line_color=None)

layout = column(p)

point_attributes = ['x', 'y']

# Point events

p.on_event(events.Tap, print_event(attributes=point_attributes))
p.on_event(events.DoubleTap, print_event(attributes=point_attributes))

curdoc().add_root(layout)

session = push_session(curdoc())

session.show()
session.loop_until_closed()

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/bd643858-1031-4161-b3b8-8e08e9514f5c%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.