7

I'm trying to set up a bokeh plot where the user can click on the plot to add a point. I've seen this example which uses the BoxSelectTool to add Rect glyphs to the plot, however I'm looking for a way to add circle glyphs centered at the click location. I would also like to then send these points back to the server side of things. Anyone have any experience doing something similar?

1
  • 1
    this question is very old, but i've posted the solution i found below because i was searching for something alike - in case it can help others Commented Apr 28, 2018 at 20:07

1 Answer 1

11

This works for me in Bokeh version 0.12.13:

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)

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

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

the reset doesn't do anything for me. bokeh server version 1.1.0
the bokeh figure reset button only resets a selection, zoom, pan,.. It does not reset your source data. If you want to reset your source data too the easiest way is to refresh your page. Otherwise you can add a button with a callback that resets your source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.