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?
-
1this 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 othersJoris– Joris2018-04-28 20:07:40 +00:00Commented Apr 28, 2018 at 20:07
Add a comment
|
1 Answer
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 )
2 Comments
Leevi L
the reset doesn't do anything for me. bokeh server version 1.1.0
Joris
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.
