0
votes

I am trying to understand how to use callbacks for the new Bokeh EditTools (e.g. BoxEditTool or similar). Specifically, I would like to see on the server side the coordinates of the newly added rectangles, but I am not sure how to do this.

I am running the following server app

def app( curdoc ):
    TOOLS = "tap"
    p = figure(title="Some Figure", tools=TOOLS)
    source = ColumnDataSource( {'xs':[1], 'ys':[1], 'width':[.1],'height':[.1]})
    r = p.rect('xs','ys','width','height', source=source)
    p.add_tools(BoxEditTool( renderers = [r]))
    def cb( attr, old, new ):
        print(r.data_source.data)
    r.data_source.on_change("selected", cb)
    curdoc.add_root(column(p))

I do get printout from the cb when I select different rectangles, but the r.data_source.data does not change

Thanks for the help!

1

1 Answers

0
votes

The behaviour you're describing is actually a bug in the current distribution of Bokeh (0.13.0). You can read more in the google groups discussion. To summarize, there was a problem with the synchronization of the data at the server, it has been resolved and merged.

Note that the on_change method for the Rect glyph ColumnDataSource should watch the 'data' attribute and not 'selected'.

Other than that your snippet looks good, but if you want a working example you can look here. This code is under development but at this stage it reads images and allows drawing ROIs, as well as a simple mechanism for serializing and loading them.

Hope this helps!