Manufacturing Tap Events

I have a very complex callback that executes on a tap event and it works just fine.

What I’m trying to do is add a feature that allows the user to import a csv of what is essentially a list of xy locations that will essentially mimic the act of tapping in those places (which will subsequently trigger my very complex callback in the desired order).

So what I’m looking for/seeking advice about is how/if I can “manufacture” tap events given a list of xy locations to “artificially” tap?

Just wondering if anyone has any thoughts/ideas on how to accomplish this before I dive deep into my existing callback to essentially write a separate version to handle this feature :-/

Edit - Guess i’ll add that the csv import part is all taken care of too.

Oh boy this some crazy stuff, but I think I figured it out. I read about the base Event class for and saw that you can kinda initialize a particular event type via json/dictionary. Then I noticed that on the JS side you can call .trigger_event on a figure object. With that in hand I messed around with what the “dictionary” input should be, and here it is.

Idea of this example is to trigger a tap event on a figure at a given location by clicking a button.

from bokeh.plotting import figure, show, save
from import Tap
from bokeh.models import CustomJS, Button
from bokeh.layouts import column

fig = figure(x_range=[0,30],y_range=[0,30])
r = fig.line(x=[0,20],y=[0,30])

#seems like 'event_name' and "tap" are recognized, the key-values are arbitrary?
d = {"event_name": "tap", 'x':10,'y':20}

#this callback to happen when the figure "feels" a tap event
cb_tap = CustomJS(args=dict(src= r.data_source)
              console.log('TAP HAPPENING')
    ['x'] = [0,cb_obj.x]
    ['y'] = [0,cb_obj.y]

#this callback to be triggered when you click the button, and all it will do is try to trigger a tap event
cb_simtap = CustomJS(args=dict(fig=fig,d=d)
btn = Button(label='simtap')


As always any elaboration on the mechanics of how this works much appreciated.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.