gebimble / machine-learning-articles

List of interesting articles on different topics of machine learning and deep learning
0 stars 0 forks source link

bokeh DoubleClick callbacks #3

Open gebimble opened 4 years ago

gebimble commented 4 years ago

TL;DR

A short example of a javascript callback in bokeh

Article Link

https://stackoverflow.com/a/50080573

Author

Joris

Key Takeaways

Useful Code Snippets

from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, Column
from bokeh.io import curdoc
from bokeh.events import DoubleTap

coordList=[]

TOOLS = "tap"
bound = 10
p = figure(title='Double click to leave a dot.',
           tools=TOOLS,width=700,height=700,
           x_range=(-bound, bound), y_range=(-bound, bound))

source = ColumnDataSource(data=dict(x=[], y=[]))   
p.circle(source=source,x='x',y='y') 

#add a dot where the click happened
def callback(event):
    Coords=(event.x,event.y)
    coordList.append(Coords) 
    source.data = dict(x=[i[0] for i in coordList], y=[i[1] for i in coordList])        
p.on_event(DoubleTap, callback)

layout=Column(p)

curdoc().add_root(layout)
mikosa01 commented 4 years ago

Please how can I run a similar code cause I have been having issues running it....

gebimble commented 4 years ago

Have you tried the command in the StackOverflow comment?

to run it save this script as something.py and run in a cmd: bokeh serve something.py --show