Bokeh Taptool return selected index

I need to get the index of a selected data point in a Bokeh plot, which needs to be the input of another function in my web application.

I am using Bokeh’s Taptool CustomJS Callback. However, I could not find a way to get the actual index of the selected point besides ‘console.log’. Is there some way to return this index to outside the JavaScript?

Below is my code. I am new to Javascript and Bokeh. Thanks for any help in advance.

codes =     """
var index_selected = source.selected['1d']['indices'][0];
source.trigger('change');
console.log(index_selected);
"""
taptool.callback = CustomJS(args=dict(source=source),code = codes)

Hi, what do you mean by "outside the JavaScript" ? Do you mean back to Python? In that case you will have to be running a Bokeh server application. Standalone Bokeh output is just static HTML and JS and has no connection to any Python runtime.

  http://bokeh.pydata.org/en/latest/docs/user_guide/server.html

Thanks,

Bryan

···

On May 22, 2018, at 17:33, Binghui Ouyang <[email protected]> wrote:

I need to get the index of a selected data point in a Bokeh plot, which needs to be the input of another function in my web application.

I am using Bokeh's Taptool CustomJS Callback. However, I could not find a way to get the actual index of the selected point besides 'console.log'. Is there some way to return this index to outside the JavaScript?

Below is my code. I am new to Javascript and Bokeh. Thanks for any help in advance.

codes =
"""
    var index_selected = source.selected['1d']['indices'][0];
    source.trigger('change');

    console.log(index_selected);
    """

taptool
.callback = CustomJS(args=dict(source=source),code = codes)

--
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/5561b95a-9902-486f-97ee-af000ae27642%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.