Unselect individual glyph using TapTool

I’d like to modify the bokeh TapTool such that tapping a glyph simply toggles whether that glyph is selected.

This would be more convenient (for my application) than the built-in behavior which doesn’t offer a way to unselect an individual glyph and also requires SHIFT be held down to select multiple glyphs.

Could this be achieved?

Thanks,

Aaron

1 Like

There is some ongoing work to rework the selection machinery, in part to be more policy based. This will probably open up more possibilities such as the one you describe, e.g. by making a custom selection policy that does what you want. But the horizon of for that is later this year. For now I think the only option is to make a custom extension tool:

  https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html

Thanks,

Bryan

···

On Jan 30, 2018, at 02:53, [email protected] wrote:

I'd like to modify the bokeh TapTool such that tapping a glyph simply toggles whether that glyph is selected.

This would be more convenient (for my application) than the built-in behavior which doesn't offer a way to unselect an individual glyph and also requires SHIFT be held down to select multiple glyphs.

Could this be achieved?

Thanks,
Aaron

--
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/d8190105-b0c9-4464-96c4-c2942df56162%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thank you, Bryan.

The extensions user guide you linked to gave me a better understanding of how Bokeh works under the hood.

-Aaron

···

On Tuesday, January 30, 2018 at 9:51:34 AM UTC-8, Bryan Van de ven wrote:

There is some ongoing work to rework the selection machinery, in part to be more policy based. This will probably open up more possibilities such as the one you describe, e.g. by making a custom selection policy that does what you want. But the horizon of for that is later this year. For now I think the only option is to make a custom extension tool:

    [https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html](https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html)

Thanks,

Bryan

On Jan 30, 2018, at 02:53, [email protected] wrote:

I’d like to modify the bokeh TapTool such that tapping a glyph simply toggles whether that glyph is selected.

This would be more convenient (for my application) than the built-in behavior which doesn’t offer a way to unselect an individual glyph and also requires SHIFT be held down to select multiple glyphs.

Could this be achieved?

Thanks,

Aaron


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/d8190105-b0c9-4464-96c4-c2942df56162%40continuum.io.

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

Ideally, the TapTool would simply trigger a callback containing the object that was clicked on. Then, the callback would modify the selected property of the source as necessary.

···

On Tuesday, January 30, 2018 at 10:40:31 AM UTC-8, Aaron Andalman wrote:

Thank you, Bryan.

The extensions user guide you linked to gave me a better understanding of how Bokeh works under the hood.

-Aaron

On Tuesday, January 30, 2018 at 9:51:34 AM UTC-8, Bryan Van de ven wrote:

There is some ongoing work to rework the selection machinery, in part to be more policy based. This will probably open up more possibilities such as the one you describe, e.g. by making a custom selection policy that does what you want. But the horizon of for that is later this year. For now I think the only option is to make a custom extension tool:

    [https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html](https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html)

Thanks,

Bryan

On Jan 30, 2018, at 02:53, [email protected] wrote:

I’d like to modify the bokeh TapTool such that tapping a glyph simply toggles whether that glyph is selected.

This would be more convenient (for my application) than the built-in behavior which doesn’t offer a way to unselect an individual glyph and also requires SHIFT be held down to select multiple glyphs.

Could this be achieved?

Thanks,

Aaron


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/d8190105-b0c9-4464-96c4-c2942df56162%40continuum.io.

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

That's possibly doable, you can set the behavior to select (default) or inspect:

  https://github.com/bokeh/bokeh/blob/master/bokeh/models/tools.py#L286

Thanks,

Bryan

···

On Jan 30, 2018, at 13:48, [email protected] wrote:

Ideally, the TapTool would simply trigger a callback containing the object that was clicked on. Then, the callback would modify the selected property of the source as necessary.

On Tuesday, January 30, 2018 at 10:40:31 AM UTC-8, Aaron Andalman wrote:
Thank you, Bryan.

The extensions user guide you linked to gave me a better understanding of how Bokeh works under the hood.

-Aaron

On Tuesday, January 30, 2018 at 9:51:34 AM UTC-8, Bryan Van de ven wrote:
There is some ongoing work to rework the selection machinery, in part to be more policy based. This will probably open up more possibilities such as the one you describe, e.g. by making a custom selection policy that does what you want. But the horizon of for that is later this year. For now I think the only option is to make a custom extension tool:

        https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html

Thanks,

Bryan

> On Jan 30, 2018, at 02:53, ner...@gmail.com wrote:
>
> I'd like to modify the bokeh TapTool such that tapping a glyph simply toggles whether that glyph is selected.
>
> This would be more convenient (for my application) than the built-in behavior which doesn't offer a way to unselect an individual glyph and also requires SHIFT be held down to select multiple glyphs.
>
> Could this be achieved?
>
> Thanks,
> Aaron
>
>
>
> --
> 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/d8190105-b0c9-4464-96c4-c2942df56162%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/aac570dd-c3d6-4922-98d8-069d0a599a94%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

That could potentially work, but it is unclear from the documentation whether the callback will receive sufficient information. The documentation states the callback will receive the TapTool as the ‘cb_obj’ and the source as the ‘cb_data’, but will it receive the index of clicked glyph within the source? In other words, if I plot a bunch of polygons using patches, will the callback specify which polygon was clicked?

Here is what the docs say:
The callback will be executed for each individual glyph that is it hit by a click or tap, and will receive the TapTool model as cb_obj. The optional cb_data will have the data source as its .source attribute and the selection geometry as its .geometries attribute.

Do you know?

I guess I could work around that by plotting with patch instead of patches, such that each polygon has its own source, but I guess this might be slow/inefficient given that I have 1000s of polygons.

-Aaron

···

On Tue, Jan 30, 2018 at 11:51 AM Bryan Van de ven [email protected] wrote:

That’s possibly doable, you can set the behavior to select (default) or inspect:

    [https://github.com/bokeh/bokeh/blob/master/bokeh/models/tools.py#L286](https://github.com/bokeh/bokeh/blob/master/bokeh/models/tools.py#L286)

Thanks,

Bryan

On Jan 30, 2018, at 13:48, [email protected] wrote:

Ideally, the TapTool would simply trigger a callback containing the object that was clicked on. Then, the callback would modify the selected property of the source as necessary.

On Tuesday, January 30, 2018 at 10:40:31 AM UTC-8, Aaron Andalman wrote:

Thank you, Bryan.

The extensions user guide you linked to gave me a better understanding of how Bokeh works under the hood.

-Aaron

On Tuesday, January 30, 2018 at 9:51:34 AM UTC-8, Bryan Van de ven wrote:

There is some ongoing work to rework the selection machinery, in part to be more policy based. This will probably open up more possibilities such as the one you describe, e.g. by making a custom selection policy that does what you want. But the horizon of for that is later this year. For now I think the only option is to make a custom extension tool:

    [https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html](https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html)

Thanks,

Bryan

On Jan 30, 2018, at 02:53, [email protected] wrote:

I’d like to modify the bokeh TapTool such that tapping a glyph simply toggles whether that glyph is selected.

This would be more convenient (for my application) than the built-in behavior which doesn’t offer a way to unselect an individual glyph and also requires SHIFT be held down to select multiple glyphs.

Could this be achieved?

Thanks,

Aaron

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/d8190105-b0c9-4464-96c4-c2942df56162%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/aac570dd-c3d6-4922-98d8-069d0a599a94%40continuum.io.

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

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

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/hokmVSya4OE/unsubscribe.

To unsubscribe from this group and all its topics, 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/4D33DB28-7033-4A9A-BFB4-DCAA87D649ED%40anaconda.com.

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

Hi,

Unfortunately I don't know 100% offhand. My hunch is that they return the necessary info, but I think the docs here could be improved. If you put a "debugger" statement in the callback, you could simple examine the contents of these objects with a JS console open. Alternatively you can add "console.log" statements for printf style debugging in the browser console. This information could be fed back to improve the docs.

Thanks,

Bryan

···

On Jan 30, 2018, at 17:10, Aaron Andalman <[email protected]> wrote:

That could potentially work, but it is unclear from the documentation whether the callback will receive sufficient information. The documentation states the callback will receive the TapTool as the 'cb_obj' and the source as the 'cb_data', but will it receive the index of clicked glyph within the source? In other words, if I plot a bunch of polygons using patches, will the callback specify which polygon was clicked?

Here is what the docs say:
The callback will be executed for each individual glyph that is it hit by a click or tap, and will receive the ``TapTool`` model as ``cb_obj``. The optional ``cb_data`` will have the data source as its ``.source`` attribute and the selection geometry as its ``.geometries`` attribute.

Do you know?

I guess I could work around that by plotting with patch instead of patches, such that each polygon has its own source, but I guess this might be slow/inefficient given that I have 1000s of polygons.

-Aaron

On Tue, Jan 30, 2018 at 11:51 AM Bryan Van de ven <[email protected]> wrote:
That's possibly doable, you can set the behavior to select (default) or inspect:

        https://github.com/bokeh/bokeh/blob/master/bokeh/models/tools.py#L286

Thanks,

Bryan

> On Jan 30, 2018, at 13:48, [email protected] wrote:
>
> Ideally, the TapTool would simply trigger a callback containing the object that was clicked on. Then, the callback would modify the selected property of the source as necessary.
>
> On Tuesday, January 30, 2018 at 10:40:31 AM UTC-8, Aaron Andalman wrote:
> Thank you, Bryan.
>
> The extensions user guide you linked to gave me a better understanding of how Bokeh works under the hood.
>
> -Aaron
>
> On Tuesday, January 30, 2018 at 9:51:34 AM UTC-8, Bryan Van de ven wrote:
> There is some ongoing work to rework the selection machinery, in part to be more policy based. This will probably open up more possibilities such as the one you describe, e.g. by making a custom selection policy that does what you want. But the horizon of for that is later this year. For now I think the only option is to make a custom extension tool:
>
> https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html
>
> Thanks,
>
> Bryan
>
> > On Jan 30, 2018, at 02:53, ner...@gmail.com wrote:
> >
> > I'd like to modify the bokeh TapTool such that tapping a glyph simply toggles whether that glyph is selected.
> >
> > This would be more convenient (for my application) than the built-in behavior which doesn't offer a way to unselect an individual glyph and also requires SHIFT be held down to select multiple glyphs.
> >
> > Could this be achieved?
> >
> > Thanks,
> > Aaron
> >
> >
> >
> > --
> > 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/d8190105-b0c9-4464-96c4-c2942df56162%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/aac570dd-c3d6-4922-98d8-069d0a599a94%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to a topic in the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/hokmVSya4OE/unsubscribe\.
To unsubscribe from this group and all its topics, 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/4D33DB28-7033-4A9A-BFB4-DCAA87D649ED%40anaconda.com\.
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/CAJU-QWrN17N42cMd6ev6QPGkuPhxLApoxhMiBRNaoeRwu6Zr%3Dw%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks for the tips. I wasn’t sure how to set a breakpoint (don’t do any front-end work) but using console.log I was able to examine cb_obj and cb_data.

Cb_data contains an x,y point (which appears to be in pixel screen units) and the source, but I don’t see an index into the source. If I could convert the point into bokeh axis units, I could manually scan the source for hits.

Alternative, I guess could remake the bokeh model such that every polygon has its own source. That could work. Not sure how much less efficient that would be.

Aaron

···

On Tue, Jan 30, 2018 at 3:19 PM Bryan Van de ven [email protected] wrote:

Hi,

Unfortunately I don’t know 100% offhand. My hunch is that they return the necessary info, but I think the docs here could be improved. If you put a “debugger” statement in the callback, you could simple examine the contents of these objects with a JS console open. Alternatively you can add “console.log” statements for printf style debugging in the browser console. This information could be fed back to improve the docs.

Thanks,

Bryan

On Jan 30, 2018, at 17:10, Aaron Andalman [email protected] wrote:

That could potentially work, but it is unclear from the documentation whether the callback will receive sufficient information. The documentation states the callback will receive the TapTool as the ‘cb_obj’ and the source as the ‘cb_data’, but will it receive the index of clicked glyph within the source? In other words, if I plot a bunch of polygons using patches, will the callback specify which polygon was clicked?

Here is what the docs say:

The callback will be executed for each individual glyph that is it hit by a click or tap, and will receive the TapTool model as cb_obj. The optional cb_data will have the data source as its .source attribute and the selection geometry as its .geometries attribute.

Do you know?

I guess I could work around that by plotting with patch instead of patches, such that each polygon has its own source, but I guess this might be slow/inefficient given that I have 1000s of polygons.

-Aaron

On Tue, Jan 30, 2018 at 11:51 AM Bryan Van de ven [email protected] wrote:

That’s possibly doable, you can set the behavior to select (default) or inspect:

    [https://github.com/bokeh/bokeh/blob/master/bokeh/models/tools.py#L286](https://github.com/bokeh/bokeh/blob/master/bokeh/models/tools.py#L286)

Thanks,

Bryan

On Jan 30, 2018, at 13:48, [email protected] wrote:

Ideally, the TapTool would simply trigger a callback containing the object that was clicked on. Then, the callback would modify the selected property of the source as necessary.

On Tuesday, January 30, 2018 at 10:40:31 AM UTC-8, Aaron Andalman wrote:

Thank you, Bryan.

The extensions user guide you linked to gave me a better understanding of how Bokeh works under the hood.

-Aaron

On Tuesday, January 30, 2018 at 9:51:34 AM UTC-8, Bryan Van de ven wrote:

There is some ongoing work to rework the selection machinery, in part to be more policy based. This will probably open up more possibilities such as the one you describe, e.g. by making a custom selection policy that does what you want. But the horizon of for that is later this year. For now I think the only option is to make a custom extension tool:

    [https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html](https://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html)

Thanks,

Bryan

On Jan 30, 2018, at 02:53, [email protected] wrote:

I’d like to modify the bokeh TapTool such that tapping a glyph simply toggles whether that glyph is selected.

This would be more convenient (for my application) than the built-in behavior which doesn’t offer a way to unselect an individual glyph and also requires SHIFT be held down to select multiple glyphs.

Could this be achieved?

Thanks,

Aaron

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/d8190105-b0c9-4464-96c4-c2942df56162%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/aac570dd-c3d6-4922-98d8-069d0a599a94%40continuum.io.

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

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

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/hokmVSya4OE/unsubscribe.

To unsubscribe from this group and all its topics, 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/4D33DB28-7033-4A9A-BFB4-DCAA87D649ED%40anaconda.com.

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/CAJU-QWrN17N42cMd6ev6QPGkuPhxLApoxhMiBRNaoeRwu6Zr%3Dw%40mail.gmail.com.

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

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

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/hokmVSya4OE/unsubscribe.

To unsubscribe from this group and all its topics, 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/276B3488-2559-4B2A-B1A8-D95169230BB0%40anaconda.com.

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

Did you solve the issue? How?
Please share your solution/approach. Many thanks!!