0

I am able to add a BoxSelectTool to my plot.

plot.add_tools(BoxSelectTool(dimensions="both"))

The tool shows up and I made a rectangular selection. But the documented method shows nothing for the selected points.

source.selected.indices

[] is returned. What is wrong. How do I get the selected indices?

after following the posts, I can get the embedded server working, and source.selected.indices does return the points, but call_back still does not work

def callback(attr, old, new):
    print('select changed')
    # The index of the selected glyph is : new['1d']['indices'][0]
    patch_name =  source.data['name'][new['1d']['indices'][0]]
    print("TapTool callback executed on Patch {}".format(patch_name))

 source.on_change('selected',callback)

any ideas please?

bhomass
  • 3,414
  • 8
  • 45
  • 75
  • Are you actually running this as a Bokeh server application (possibly embedded in a notebook)? If not, if you are just calling `show` or `save` to generate static HTML output, then there is no synchronization between python and the browser (the Bokeh server *is the thing* that performs such a synchronization). – bigreddot Jan 25 '20 at 19:33
  • Thanks for the comment. This is in a jupyter notebook, so no Bokeh server is involved. So in case of running everything is a notebook, how do I access the source.selected.indices? I would embed the server in the notebook? can you show me how? – bhomass Jan 27 '20 at 02:52
  • I followed https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/notebook_embed.ipynb. but nothing is showing – bhomass Jan 27 '20 at 03:01
  • tried this as well.https://stackoverflow.com/questions/53217654/how-to-get-interactive-bokeh-in-jupyter-notebook still nothing displayed. – bhomass Jan 27 '20 at 03:18
  • If you want the value to sync, there is definitely the Bokeh server involved, although it can be embedded in the notebook as your first link demonstrates. At this point you really need to provide or link to a complete minimal notebook, it's not possible to help without seeing what you are actually doing. – bigreddot Jan 27 '20 at 03:40
  • I simply need to get either of the two links to work. Once they work, I will fill in anything that is specific to my requirements. Any idea why the code from the two links don't work? The first one seems to point to something like the right url (port number) needs to be used or specified, but I have no idea how that's done. certainly, my notebook is taking up port 8888 already. So if I set up another url, do I open another browser to receive it? I am confused. – bhomass Jan 28 '20 at 03:16
  • `notebook_url` needs to be set to the URL location of the notebook that is running, i.e. the name and port in your URL bar right there. If the notebook is running locally on the default port, i.e. if it is `localhost:8888` then that is already the default value for `notebook_url`. You only ned to set `notebook_url` if your notebook window is at some address that is not the default `localhost:8888`. – bigreddot Jan 29 '20 at 07:27
  • And if you are not running the notebook server locally, i.e. if "ipython notebook" is running on some remote machine, then it's entirely possible there are other network configuration issues. The Bokeh server communicates via websocket, so if there is some proxy in between your local browser and the remote notebook server that is blocking websocket connections, then it will not work. – bigreddot Jan 29 '20 at 07:29
  • all right. so it was just a matter of using ip directly instead of the host I defined locally when declared the url. Thank you very much. – bhomass Feb 02 '20 at 00:21
  • well, I got the embedded server working, and source.selected.indices is showing the selected data points, but call_back still doesn't respond. def callback(attr, old, new): print('select changed') # The index of the selected glyph is : new['1d']['indices'][0] patch_name = source.data['name'][new['1d']['indices'][0]] print("TapTool callback executed on Patch {}".format(patch_name)) source.on_change('selected',callback) any ideas please? – bhomass Feb 02 '20 at 01:13
  • The "1d" notation was deprecated some time ago (and will be removed entirely in the upcoming 2.0 release). It should not be used. You should only use `source.selected.indices` and in particular that call back should be on `source.selected.on_change('indices', ...)` There are lots of examples in the docs and repo that demonstrate this exact pattern. See also the migration notes in the relevant release notes: http://docs.bokeh.org/en/dev/docs/releases.html#release-0-12-15 – bigreddot Feb 02 '20 at 01:52
  • Also, as a suggestion, for more open-ended questions like this, the Bokeh Project Discourse is probably a better venue: https://discourse.bokeh.org/ – bigreddot Feb 02 '20 at 01:54
  • 1
    thank you. now it works. I will post in bokeh forum instead. – bhomass Feb 03 '20 at 02:44

0 Answers0