Exporting/parsing the edit tools selections into the scripts

Hello I am starting to use bokeh (with streamlit) and I am researching the JS callback functions.

I wanted to confirm if it is possible to export recursively the selection regions from a bokeh plot into the parent script via a callback. For example with the BoxEditTool:

> from bokeh.plotting import figure, output_file, show
> from bokeh.models import BoxEditTool, ColumnDataSource
> output_file("tools_box_edit.html")
> p = figure(x_range=(0, 10), y_range=(0, 10), width=400, height=400,
>            title='Box Edit Tool')
> src = ColumnDataSource({
>     'x': [5, 2, 8], 'y': [5, 7, 8], 'width': [2, 1, 2],
>     'height': [2, 1, 1.5], 'alpha': [0.5, 0.5, 0.5]
> })
> renderer = p.rect('x', 'y', 'width', 'height', source=src, alpha='alpha')
> draw_tool = BoxEditTool(renderers=[renderer], empty_value=1)
> p.add_tools(draw_tool)
> p.toolbar.active_drag = draw_tool
> show(p)

Is it possible to parse the rectangles dimensions (‘x’, ‘y’, ‘width’, ‘height’,) to a dictionary or dataframe without saving to a file first using a callback?

Thanks for any advice.

@Vital-Fernandez I am sorry but I don’t really understand your question. I especially don’t understand how this would relate to recursion in any way.

Generally, I will simply state that the box edit tool store the data for the rects in a ColumnDataSource and you can trigger JS callbacks (or Python callbacks, if you are running a Bokeh server app) to happen when that data source is updated.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.