how to get box tool geometry to server side bokeh

Hi,

I am trying to get geometry attribute of box tool. However, I want to use these values on server side. What I would normally do was to define a CustomJs callback function on box select tool but in this case, it doesn’t work out. Could you please explain me how can I achieve this?

Thanks

Hi,

Take a look at this examples, particularly the SelectionGeometry part:

  https://github.com/bokeh/bokeh/blob/master/examples/howto/events_app.py

Thanks,

Bryan

···

On Jun 9, 2018, at 09:17, [email protected] wrote:

Hi,

I am trying to get geometry attribute of box tool. However, I want to use these values on server side. What I would normally do was to define a CustomJs callback function on box select tool but in this case, it doesn't work out. Could you please explain me how can I achieve this?

Thanks

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/62f53b52-9e7f-4b40-9951-cf2b24f9a69e%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks for reply, upon checking the link and writing the below code. I get None is not a callable object error when running,

from bokeh.plotting import figure, output_file, show

from bokeh import events

from bokeh.models import CustomJS,ColumnDataSource,Slider,DataRange1d,HoverTool,Legend,LinearAxis,BoxSelectTool,Rect#,GMapOptions,WMTSTileSource

output to static HTML file

callbackBoxSelect = CustomJS(code = “”" console.log(“yey2”) “”")

box_selectMap = BoxSelectTool(callback=callbackBoxSelect)

output_file(“line.html”)

tools=‘pan,wheel_zoom,reset’

def print_event(attributes = ):

print(“yey”)

p = figure(plot_width=400, plot_height=400,tools=[tools,box_selectMap])

p.on_event(events.SelectionGeometry, print_event(attributes=[‘geometry’, ‘final’]))

add a circle renderer with a size, color, and alpha

p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color=“navy”, alpha=0.5)

show the results

show(p)

···

On Saturday, June 9, 2018 at 7:24:42 PM UTC+3, Bryan Van de ven wrote:

Hi,

Take a look at this examples, particularly the SelectionGeometry part:

    [https://github.com/bokeh/bokeh/blob/master/examples/howto/events_app.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/events_app.py)

Thanks,

Bryan

On Jun 9, 2018, at 09:17, [email protected] wrote:

Hi,

I am trying to get geometry attribute of box tool. However, I want to use these values on server side. What I would normally do was to define a CustomJs callback function on box select tool but in this case, it doesn’t work out. Could you please explain me how can I achieve this?

Thanks


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/62f53b52-9e7f-4b40-9951-cf2b24f9a69e%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

There are at least two issues:

* callbacks have a defined signature, and the callback you are passing is not correct. The callback must look like:

    def python_callback(event):

If you look at the the linked example, you can see the "print_event" is not actually the callback that is registered, instead it is a function that *creates* the callback (with the signature above). The error message given is not a great one, perhaps we can make it better

* Also by using output_file and show, you are creating a "standalone" bokeh document. I.e. not an app that runs on the bokeh server. But real Python callbacks, i.e. those added with "on_event" can ONLY work on the bokeh server. That's because standalone bokeh docs are just HTML/JS and the browser has no ability to run python code or callbacks. For information about running and deploying Bokeh server apps, see

  Bokeh server — Bokeh 3.3.2 Documentation

Thanks,

Bryan

···

On Jun 9, 2018, at 09:43, [email protected] wrote:

Thanks for reply, upon checking the link and writing the below code. I get None is not a callable object error when running,

from bokeh.plotting import figure, output_file, show
from bokeh import events
from bokeh.models import CustomJS,ColumnDataSource,Slider,DataRange1d,HoverTool,Legend,LinearAxis,BoxSelectTool,Rect#,GMapOptions,WMTSTileSource
# output to static HTML file
callbackBoxSelect = CustomJS(code = """ console.log("yey2") """)
box_selectMap = BoxSelectTool(callback=callbackBoxSelect)
output_file("line.html")
tools='pan,wheel_zoom,reset'
def print_event(attributes = ):
    print("yey")
p = figure(plot_width=400, plot_height=400,tools=[tools,box_selectMap])
p.on_event(events.SelectionGeometry, print_event(attributes=['geometry', 'final']))
# add a circle renderer with a size, color, and alpha
p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)

# show the results
show(p)

On Saturday, June 9, 2018 at 7:24:42 PM UTC+3, Bryan Van de ven wrote:
Hi,

Take a look at this examples, particularly the SelectionGeometry part:

        https://github.com/bokeh/bokeh/blob/master/examples/howto/events_app.py

Thanks,

Bryan

> On Jun 9, 2018, at 09:17, koseog...@gmail.com wrote:
>
> Hi,
>
> I am trying to get geometry attribute of box tool. However, I want to use these values on server side. What I would normally do was to define a CustomJs callback function on box select tool but in this case, it doesn't work out. Could you please explain me how can I achieve this?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/62f53b52-9e7f-4b40-9951-cf2b24f9a69e%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/aa1edf33-a7e4-4520-981f-b634d1af0eb2%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.