What changed with javascript selection in version 0.12.15 and beyond?

I hit a problem with JS callback based selections in version 13, but discovered it still worked in an older version (0.12.10). I narrowed it down to a change in 0.12.15 which I suppose might be related to https://github.com/bokeh/bokeh/issues/6845

This stylised example was lifted straight from the v13 doc’s, and simply forces the selection of point 2 on the chart no matter which point is chosen.

What am I missing here?

from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.models.tools import HoverTool, TapTool
from bokeh.io import reset_output, output_file, save
import pandas as pd

s = ColumnDataSource(pd.DataFrame({‘x’: [1, 2, 3, 4, 5], ‘y’: [2, 5, 8, 2, 7]}))
plot = figure(plot_width=400, plot_height=400, tools=, title=“Select a circle”)
renderer = plot.circle(‘x’, ‘y’, source=s, size=50,

                   # set visual properties for selected glyphs
                   selection_color="firebrick",

                   # set visual properties for non-selected glyphs
                   nonselection_fill_alpha=0.2,
                   nonselection_fill_color="blue",
                   nonselection_line_color="firebrick",
                   nonselection_line_alpha=1.0)

tap_code = “”"
console.log(source.selected[‘1d’].indices);
source.selected[‘1d’].indices = [2];
source.change.emit();
console.log(source.selected[‘1d’].indices);
“”"
tap_callback = CustomJS(code = tap_code, args={‘source’: s})

plot.add_tools(TapTool(callback=tap_callback))

output_file(r’C:\data\test.html’)
save(plot)
reset_output()

``

Hi Kevin,

I just want to chime in saying I also found the bug since that version when trying to use selection (1D and 2D) for the network graph stuff. My manual selection and emitting of changes stopped working when I upgraded to that version.

Also curious what to do…

···

On Jul 30, 2018, at 9:09 AM, Kevin O’Donnell [email protected] wrote:

I hit a problem with JS callback based selections in version 13, but discovered it still worked in an older version (0.12.10). I narrowed it down to a change in 0.12.15 which I suppose might be related to https://github.com/bokeh/bokeh/issues/6845

This stylised example was lifted straight from the v13 doc’s, and simply forces the selection of point 2 on the chart no matter which point is chosen.

What am I missing here?

from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.models.tools import HoverTool, TapTool
from bokeh.io import reset_output, output_file, save
import pandas as pd

s = ColumnDataSource(pd.DataFrame({‘x’: [1, 2, 3, 4, 5], ‘y’: [2, 5, 8, 2, 7]}))
plot = figure(plot_width=400, plot_height=400, tools=, title=“Select a circle”)
renderer = plot.circle(‘x’, ‘y’, source=s, size=50,

                   # set visual properties for selected glyphs
                   selection_color="firebrick",

                   # set visual properties for non-selected glyphs
                   nonselection_fill_alpha=0.2,
                   nonselection_fill_color="blue",
                   nonselection_line_color="firebrick",
                   nonselection_line_alpha=1.0)

tap_code = “”"
console.log(source.selected[‘1d’].indices);
source.selected[‘1d’].indices = [2];
source.change.emit();
console.log(source.selected[‘1d’].indices);
“”"
tap_callback = CustomJS(code = tap_code, args={‘source’: s})

plot.add_tools(TapTool(callback=tap_callback))

output_file(r’C:\data\test.html’)
save(plot)
reset_output()

``

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/143ee870-9508-4c33-93ee-1653047a4354%40continuum.io.

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

Is this a bug?

I would guess a regression unless the ways we were manipulating the selected indices and then emitting the changes was supposed to be changed. Unfortunately after a quick investigation I had to move onto another part of the project :frowning:

···

On Wed, Aug 1, 2018 at 4:42 AM Kevin O’Donnell [email protected] wrote:

Is this a bug?

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/b8a5c482-ec7b-4065-b911-4e65c5e93a3e%40continuum.io.

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

Hi,

In 0.12.15 selections were changed from being a "bare dict" with keys "1d", etc. to being a proper Bokeh model with individual selection properties that could be synchronized in the standard way as all other properties. This was a long overdue change, as the "bare dict" approach had several hopeless issues that could not be addressed otherwise.

As always, when there is an intentional change like this, we provide information in the release notes migration guide:

  https://bokeh.pydata.org/en/latest/docs/releases.html#selections

Hovever, even when there are intentional changes, and they are duly noted, there can be unintentional effects, and that happened in this instance. Now that "source.selected" is a real Bokeh model, with "indices" as property, there are actually two ways that updates might trigger:

* The selection object itself can be replaced, or
* The indices property on a selection object can be changed

This has caused both some confusion, as well as some actual regressions. I am about to start work on a PR to clarify these cases and make it so that there are reasonable expectations about how to structure things going forward. But TLDR, you most likely want to have callbacks such as:

  source.selected.on_change('indices, ...)

or

  source.selected.js_on_change('indices, ...)

It would (as always) be easier to provide better concrete guidance with a complete minimal example.

Given the impact of changing how selections work at the low level, I would have ideally preferred to have bean able to make this change long ago, but that's unfortunately not what we were able to accomplish given the resources that were available to us. As an example, until very recently, our integration test framework for selenium and other end-to-end interaction testing was broken, and had been for some time, and no one was available to devote time to fixing it. Several regressions slipped through as a result of this alone. Now that those tests are functional again, I look forward to placing a very large number of interactive use-cases under more rigorous integration test. However the main lesson is this: if you have the ability to help contribute to making Bokeh better and more stable, please do get involved, as it should be obvious to see that the project can use more eyes and hands.

Thanks,

Bryan

···

On Jul 31, 2018, at 23:44, 'Corey O'Meara' via Bokeh Discussion - Public <[email protected]> wrote:

I would guess a regression unless the ways we were manipulating the selected indices and then emitting the changes was supposed to be changed. Unfortunately after a quick investigation I had to move onto another part of the project :frowning:

On Wed, Aug 1, 2018 at 4:42 AM Kevin O'Donnell <[email protected]> wrote:
Is this a bug?

--
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/b8a5c482-ec7b-4065-b911-4e65c5e93a3e%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/CAAoKuhL0st3BZrRV0eCnYAeyQLD%2BFbfk4fp-YJDsAMCT7g4mCw%40mail.gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thanks Bryan,

For future readers, the only change that was needed in the original example was this:

tap_code = “”"
console.log(source.selected[‘1d’].indices); // the selected items can still be READ from here.
source.selected.indices = [2]; // But any change in selection must be done like this.
source.change.emit();
console.log(source.selected[‘1d’].indices);
“”"

``