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

[BUG] Python callback triggered by SelectionGeometry event is slow compared to js equivalent #11169

Closed
MesicBenjamin opened this issue Apr 15, 2021 · 0 comments · Fixed by #11194

Comments

@MesicBenjamin
Copy link

Version: Bokeh 2.3.1, tested on Chrome and Safari (MacOS BigSur)

Problem: Python callback triggered by SelectionGeometry event is slow compared to js equivalent. This behaviour is present both for lasso_select and box_select.

Discussion about this topic exists here:
https://discourse.bokeh.org/t/python-callback-triggered-by-selectiongeometry-event-is-slow-compared-to-js-equivalent/7620

Note: Works fine with Bokeh 2.2.x

from bokeh.models import CustomJS
from bokeh.plotting import figure, output_notebook, show
from bokeh.events import SelectionGeometry
from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
import numpy as np

output_notebook()

# Choose 'python' or 'js'
case = 'python'

def f(doc):

    N = 1000
    img = np.empty((N,N), dtype=np.uint32)
    view = img.view(dtype=np.uint8).reshape((N, N, 4))
    for i in range(N):
        for j in range(N):
            view[i, j, 0] = int(i/N*255)
            view[i, j, 1] = 158
            view[i, j, 2] = int(j/N*255)
            view[i, j, 3] = 255
    plot = figure(tools="lasso_select, box_select, wheel_zoom")
    plot.image_rgba(image=[img], x=0, y=0, dw=10, dh=10)

    if case == 'python':
        plot.on_event(SelectionGeometry, lambda x: None)
        
    else:
        plot.js_on_event(SelectionGeometry, CustomJS(code=""" """))

    doc.add_root(plot)
    
    return doc
    
handler = FunctionHandler(f)
app = Application(handler)

show(app)

@MesicBenjamin MesicBenjamin changed the title [BUG] [BUG] Python callback triggered by SelectionGeometry event is slow compared to js equivalent Apr 15, 2021
@mattpap mattpap added this to the 2.3.2 milestone Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants