Bokeh EditTools callback to server

久未见 提交于 2019-12-11 19:53:30

问题


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:


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!



来源:https://stackoverflow.com/questions/48743494/bokeh-edittools-callback-to-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!