How do I do pre-selection on rows in a Bokeh DataTable and display such selection?

I am so glad this group exists (just discovered it), as I am having an issue I can’t solve by myself.

Assume I have a DataTable like so:

data = dict(
index = list(range(10)),
x = list(range(10)),
y = list(range(10)),
z = [‘some other data’] * 10
)

source1 = ColumnDataSource(data)
columns = [
TableColumn(field=“y”, title=“Y”),
TableColumn(field=“z”, title=“Text”),
]
data_table = DataTable(source=source1, columns=columns, width=400, height=280)

Let’s assume there is something important about row 1, and 5, and therefore these rows should get “selected” by default when the table gets rendered. How would such a feat be accomplished? So far I have tried the following:

1.) On the Python side:

source1.selected[‘1d’].indices = [0, 4]

After the above line is executed, the indices are indeed correctly set. But I am not getting the corresponding rows to get highlighted like they do when I actually click on said rows.

2.) As a CustomJS:

source1[‘selected’][‘1d’].indices = [0, 4]

Again, I see no change in highlighting. Quite apart from that, I don’t know how you would pass in lists into JSCustom because JSCustom only takes Bokeh related items in as “args”.

What can I do to get row highlighting to work? Is that possible at all? I should add I am on Bokeh 12.4 and using Python 3.5.

I should also add that I am trying to get this to work within the context of a Bokeh server application.

···

On Friday, July 14, 2017 at 3:12:26 PM UTC-7, Anthony Le wrote:

I am so glad this group exists (just discovered it), as I am having an issue I can’t solve by myself.

Assume I have a DataTable like so:

data = dict(
index = list(range(10)),
x = list(range(10)),
y = list(range(10)),
z = [‘some other data’] * 10
)

source1 = ColumnDataSource(data)
columns = [
TableColumn(field=“y”, title=“Y”),
TableColumn(field=“z”, title=“Text”),
]
data_table = DataTable(source=source1, columns=columns, width=400, height=280)

Let’s assume there is something important about row 1, and 5, and therefore these rows should get “selected” by default when the table gets rendered. How would such a feat be accomplished? So far I have tried the following:

1.) On the Python side:

source1.selected[‘1d’].indices = [0, 4]

After the above line is executed, the indices are indeed correctly set. But I am not getting the corresponding rows to get highlighted like they do when I actually click on said rows.

2.) As a CustomJS:

source1[‘selected’][‘1d’].indices = [0, 4]

Again, I see no change in highlighting. Quite apart from that, I don’t know how you would pass in lists into JSCustom because JSCustom only takes Bokeh related items in as “args”.

What can I do to get row highlighting to work? Is that possible at all? I should add I am on Bokeh 12.4 and using Python 3.5.

It's possible that this is a bug, but since you are on 0.12.4 it's also possible that it has since been fixed (there was some work on tables only recently). It's also possible there is just a usage error. With a complete code sample I could run, I could probably narrow down which case this is immediately. Can you share a complete test script to reproduce what you are seeing?

Thanks,

Bryan

···

On Jul 14, 2017, at 17:14, Anthony Le <[email protected]> wrote:

I should also add that I am trying to get this to work within the context of a Bokeh server application.

On Friday, July 14, 2017 at 3:12:26 PM UTC-7, Anthony Le wrote:
I am so glad this group exists (just discovered it), as I am having an issue I can't solve by myself.

Assume I have a DataTable like so:

data = dict(
        index = list(range(10)),
        x = list(range(10)),
        y = list(range(10)),
        z = ['some other data'] * 10
    )

source1 = ColumnDataSource(data)
columns = [
        TableColumn(field="y", title="Y"),
        TableColumn(field="z", title="Text"),
    ]
data_table = DataTable(source=source1, columns=columns, width=400, height=280)

Let's assume there is something important about row 1, and 5, and therefore these rows should get "selected" by default when the table gets rendered. How would such a feat be accomplished? So far I have tried the following:

1.) On the Python side:

source1.selected['1d'].indices = [0, 4]

After the above line is executed, the indices are indeed correctly set. But I am not getting the corresponding rows to get highlighted like they do when I actually click on said rows.

2.) As a CustomJS:

source1['selected']['1d'].indices = [0, 4]

Again, I see no change in highlighting. Quite apart from that, I don't know how you would pass in lists into JSCustom because JSCustom only takes Bokeh related items in as "args".

What can I do to get row highlighting to work? Is that possible at all? I should add I am on Bokeh 12.4 and using Python 3.5.

--
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/997a3271-f24c-4bbf-bfb9-d3c7947757d1%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

With pleasure. To troubleshoot things, I am just working on clairetang’s original code describing the problem of filterable CDS:

source2 = ColumnDataSource(filtered_data)

fig1 = figure(plot_width=300, plot_height=300)
fig1.circle(x=‘x’, y=‘y’, size=10, source=source1)

columns = [
TableColumn(field=“y”, title=“Y”),
TableColumn(field=“z”, title=“Text”),
]
data_table = DataTable(source=source2, columns=columns, width=400, height=280)

button = Button(label=“Select”)
button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""
source2[‘selected’][‘1d’].indices =[1,2,3]
var inds_in_source2 = source2[‘selected’][‘1d’].indices;

    var d = source2['data'];
    var inds = []

    if (inds_in_source2.length == 0) { return; }

    for (i = 0; i < inds_in_source2.length; i++) {
        ind2 = inds_in_source2[i]
        inds.push(d['index'][ind2])
    }

    source1['selected']['1d'].indices = inds
    source1.trigger('change');
""")

bokeh.io.output_notebook()
bokeh.io.show(column(fig1, data_table, button))

Hitting the select button SHOULD highlight rows 1, 2, 3. But in Bokeh 12.4 only the graph gets updated. The DataTable still has no rows highlighted.

The previous code tests out setting selected rows from the javascript side. This next code snippet tests setting selected rows from the python side:

from datetime import date
from random import randint
import bokeh
import bokeh.plotting

data = dict(dates=[date(2014, 3, i+1) for i in range(10)],
downloads=[randint(0, 100) for i in range(10)])

source = bokeh.models.ColumnDataSource(data)

columns = [bokeh.models.TableColumn(field=“dates”, title=“Date”,
formatter=bokeh.models.DateFormatter()),
bokeh.models.TableColumn(field=“downloads”, title=“Downloads”)]

index = [1,2]
nothing = {‘test’: [1]}
source.callback = bokeh.models.CustomJS(args=dict(source=source), code="""
console.log( ‘#Selected rows:’);
var indices = source.selected[“1d”].indices;
for (var i = 0; i<indices.length; i++){
console.log(i+":"+indices[i]);
}
//source.selected[“1d”].indices = ind
“”")

source.selected[‘1d’][‘indices’] = [1,2]
data_table = bokeh.models.DataTable(source=source, columns=columns,
width=400, height=280, editable=True)

bokeh.io.output_notebook()
bokeh.io.show(data_table)

In either case, the rows I am interested in do not get highlighted

Apologies, but this is not a complete script that I can just run as-is at the command line. Not trying to be difficult but there's only a handful of core devs and a great many users. With so many support inquiries every day, trying to deal with things that are incomplete adds up to a substantial burden on a handful of individuals. As I said, if I can run something immediately at the command line I can often immediately offer help, or at least discern where the problem is, so I'm happy to look a close look at anything I can just run "python test.py" on.

Thanks,

Bryan

···

On Jul 14, 2017, at 17:46, Anthony Le <[email protected]> wrote:

With pleasure. To troubleshoot things, I am just working on clairetang's original code describing the problem of filterable CDS:

source2 = ColumnDataSource(filtered_data)

fig1 = figure(plot_width=300, plot_height=300)
fig1.circle(x='x', y='y', size=10, source=source1)

columns = [
        TableColumn(field="y", title="Y"),
        TableColumn(field="z", title="Text"),
    ]
data_table = DataTable(source=source2, columns=columns, width=400, height=280)

button = Button(label="Select")
button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""
        source2['selected']['1d'].indices =[1,2,3]
        var inds_in_source2 = source2['selected']['1d'].indices;

        var d = source2['data'];
        var inds =

        if (inds_in_source2.length == 0) { return; }

        for (i = 0; i < inds_in_source2.length; i++) {
            ind2 = inds_in_source2[i]
            inds.push(d['index'][ind2])
        }

        source1['selected']['1d'].indices = inds
        source1.trigger('change');
    """)
bokeh.io.output_notebook()
bokeh.io.show(column(fig1, data_table, button))

Hitting the select button SHOULD highlight rows 1, 2, 3. But in Bokeh 12.4 only the graph gets updated. The DataTable still has no rows highlighted.

--
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/421feed4-35b1-49e1-8b0d-011a4d7c71bc%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Got it, I will try to convert the above into a test.py file.

···

On Friday, July 14, 2017 at 4:22:25 PM UTC-7, Bryan Van de ven wrote:

Apologies, but this is not a complete script that I can just run as-is at the command line. Not trying to be difficult but there’s only a handful of core devs and a great many users. With so many support inquiries every day, trying to deal with things that are incomplete adds up to a substantial burden on a handful of individuals. As I said, if I can run something immediately at the command line I can often immediately offer help, or at least discern where the problem is, so I’m happy to look a close look at anything I can just run “python test.py” on.

Thanks,

Bryan

On Jul 14, 2017, at 17:46, Anthony Le [email protected] wrote:

With pleasure. To troubleshoot things, I am just working on clairetang’s original code describing the problem of filterable CDS:

source2 = ColumnDataSource(filtered_data)

fig1 = figure(plot_width=300, plot_height=300)

fig1.circle(x=‘x’, y=‘y’, size=10, source=source1)

columns = [

    TableColumn(field="y", title="Y"),
    TableColumn(field="z", title="Text"),
]

data_table = DataTable(source=source2, columns=columns, width=400, height=280)

button = Button(label=“Select”)

button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""

    source2['selected']['1d'].indices =[1,2,3]
    var inds_in_source2 = source2['selected']['1d'].indices;
    var d = source2['data'];
    var inds = []
    if (inds_in_source2.length == 0) { return; }
    for (i = 0; i < inds_in_source2.length; i++) {
        ind2 = inds_in_source2[i]
        inds.push(d['index'][ind2])
    }
    source1['selected']['1d'].indices = inds
    source1.trigger('change');
""")

bokeh.io.output_notebook()

bokeh.io.show(column(fig1, data_table, button))

Hitting the select button SHOULD highlight rows 1, 2, 3. But in Bokeh 12.4 only the graph gets updated. The DataTable still has no rows highlighted.


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/421feed4-35b1-49e1-8b0d-011a4d7c71bc%40continuum.io.

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

2 things:

1.) The two files have been attached to this message.
2.) Also a heartfelt thank you for looking at this. As a developer myself, I understand the problems of a lot of work and interuptions a lot.

test_highlight_from_python.py (1022 Bytes)

test_highlight_from_CustomJS.py (1.68 KB)

···

On Friday, July 14, 2017 at 4:22:25 PM UTC-7, Bryan Van de ven wrote:

Apologies, but this is not a complete script that I can just run as-is at the command line. Not trying to be difficult but there’s only a handful of core devs and a great many users. With so many support inquiries every day, trying to deal with things that are incomplete adds up to a substantial burden on a handful of individuals. As I said, if I can run something immediately at the command line I can often immediately offer help, or at least discern where the problem is, so I’m happy to look a close look at anything I can just run “python test.py” on.

Thanks,

Bryan

On Jul 14, 2017, at 17:46, Anthony Le [email protected] wrote:

With pleasure. To troubleshoot things, I am just working on clairetang’s original code describing the problem of filterable CDS:

source2 = ColumnDataSource(filtered_data)

fig1 = figure(plot_width=300, plot_height=300)

fig1.circle(x=‘x’, y=‘y’, size=10, source=source1)

columns = [

    TableColumn(field="y", title="Y"),
    TableColumn(field="z", title="Text"),
]

data_table = DataTable(source=source2, columns=columns, width=400, height=280)

button = Button(label=“Select”)

button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""

    source2['selected']['1d'].indices =[1,2,3]
    var inds_in_source2 = source2['selected']['1d'].indices;
    var d = source2['data'];
    var inds = []
    if (inds_in_source2.length == 0) { return; }
    for (i = 0; i < inds_in_source2.length; i++) {
        ind2 = inds_in_source2[i]
        inds.push(d['index'][ind2])
    }
    source1['selected']['1d'].indices = inds
    source1.trigger('change');
""")

bokeh.io.output_notebook()

bokeh.io.show(column(fig1, data_table, button))

Hitting the select button SHOULD highlight rows 1, 2, 3. But in Bokeh 12.4 only the graph gets updated. The DataTable still has no rows highlighted.


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/421feed4-35b1-49e1-8b0d-011a4d7c71bc%40continuum.io.

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

Hi,

Thanks for the kind words. After running these examples and a little investigation, there is definitely an issue. The proximate cause is that this line:

  https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/widgets/tables/data_table.coffee#L115

is returning [-1, -1, -1] for permuted_indices when the selection is set. Hopefully something simple to fix. Can you make a GitHub issue with these scripts attached? Thanks!

Bryan

PS, FYI for 0.12.6, I modified your callback as follows:

    button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""
        source2.selected['1d'].indices = [1,2,3];
        var inds_in_source2 = source2.selected['1d'].indices;

        var d = source2['data'];
        var inds =

        if (inds_in_source2.length == 0) { return; }

        for (i = 0; i < inds_in_source2.length; i++) {
            ind2 = inds_in_source2[i]
            inds.push(d['index'][ind2])
        }
        source1.selected['1d'].indices = inds
        source1.change.emit()

        source2.properties.selected.change.emit();
        console.log(source2)
    """)

···

On Jul 14, 2017, at 18:42, Anthony Le <[email protected]> wrote:

2 things:

1.) The two files have been attached to this message.
2.) Also a heartfelt thank you for looking at this. As a developer myself, I understand the problems of a lot of work and interuptions a lot.

On Friday, July 14, 2017 at 4:22:25 PM UTC-7, Bryan Van de ven wrote:
Apologies, but this is not a complete script that I can just run as-is at the command line. Not trying to be difficult but there's only a handful of core devs and a great many users. With so many support inquiries every day, trying to deal with things that are incomplete adds up to a substantial burden on a handful of individuals. As I said, if I can run something immediately at the command line I can often immediately offer help, or at least discern where the problem is, so I'm happy to look a close look at anything I can just run "python test.py" on.

Thanks,

Bryan

> On Jul 14, 2017, at 17:46, Anthony Le <[email protected]> wrote:
>
> With pleasure. To troubleshoot things, I am just working on clairetang's original code describing the problem of filterable CDS:
>
> source2 = ColumnDataSource(filtered_data)
>
> fig1 = figure(plot_width=300, plot_height=300)
> fig1.circle(x='x', y='y', size=10, source=source1)
>
> columns = [
> TableColumn(field="y", title="Y"),
> TableColumn(field="z", title="Text"),
> ]
> data_table = DataTable(source=source2, columns=columns, width=400, height=280)
>
> button = Button(label="Select")
> button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""
> source2['selected']['1d'].indices =[1,2,3]
> var inds_in_source2 = source2['selected']['1d'].indices;
>
> var d = source2['data'];
> var inds =
>
> if (inds_in_source2.length == 0) { return; }
>
> for (i = 0; i < inds_in_source2.length; i++) {
> ind2 = inds_in_source2[i]
> inds.push(d['index'][ind2])
> }
>
> source1['selected']['1d'].indices = inds
> source1.trigger('change');
> """)
> bokeh.io.output_notebook()
> bokeh.io.show(column(fig1, data_table, button))
>
> Hitting the select button SHOULD highlight rows 1, 2, 3. But in Bokeh 12.4 only the graph gets updated. The DataTable still has no rows highlighted.
>
> --
> 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/421feed4-35b1-49e1-8b0d-011a4d7c71bc%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/b7935085-d975-4f4c-be03-e334956b01d5%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
<test_highlight_from_python.py><test_highlight_from_CustomJS.py>

Further info, the reason permuted_indices is [-1, -1, -1] is because "selected_indices" right above is [7, 8, 9] (not [1,2,3]) I expect this is some unforeseen interaction specific to filtered data sources. Definitely make the issue and I will add this information and ping Claire on it

Thanks,

Bryan

···

On Jul 14, 2017, at 19:02, Bryan Van de ven <[email protected]> wrote:

Hi,

Thanks for the kind words. After running these examples and a little investigation, there is definitely an issue. The proximate cause is that this line:

  https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/widgets/tables/data_table.coffee#L115

is returning [-1, -1, -1] for permuted_indices when the selection is set. Hopefully something simple to fix. Can you make a GitHub issue with these scripts attached? Thanks!

Bryan

PS, FYI for 0.12.6, I modified your callback as follows:

   button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""
       source2.selected['1d'].indices = [1,2,3];
       var inds_in_source2 = source2.selected['1d'].indices;

       var d = source2['data'];
       var inds =

       if (inds_in_source2.length == 0) { return; }

       for (i = 0; i < inds_in_source2.length; i++) {
           ind2 = inds_in_source2[i]
           inds.push(d['index'][ind2])
       }
       source1.selected['1d'].indices = inds
       source1.change.emit()

       source2.properties.selected.change.emit();
       console.log(source2)
   """)

On Jul 14, 2017, at 18:42, Anthony Le <[email protected]> wrote:

2 things:

1.) The two files have been attached to this message.
2.) Also a heartfelt thank you for looking at this. As a developer myself, I understand the problems of a lot of work and interuptions a lot.

On Friday, July 14, 2017 at 4:22:25 PM UTC-7, Bryan Van de ven wrote:
Apologies, but this is not a complete script that I can just run as-is at the command line. Not trying to be difficult but there's only a handful of core devs and a great many users. With so many support inquiries every day, trying to deal with things that are incomplete adds up to a substantial burden on a handful of individuals. As I said, if I can run something immediately at the command line I can often immediately offer help, or at least discern where the problem is, so I'm happy to look a close look at anything I can just run "python test.py" on.

Thanks,

Bryan

On Jul 14, 2017, at 17:46, Anthony Le <[email protected]> wrote:

With pleasure. To troubleshoot things, I am just working on clairetang's original code describing the problem of filterable CDS:

source2 = ColumnDataSource(filtered_data)

fig1 = figure(plot_width=300, plot_height=300)
fig1.circle(x='x', y='y', size=10, source=source1)

columns = [
       TableColumn(field="y", title="Y"),
       TableColumn(field="z", title="Text"),
   ]
data_table = DataTable(source=source2, columns=columns, width=400, height=280)

button = Button(label="Select")
button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""
       source2['selected']['1d'].indices =[1,2,3]
       var inds_in_source2 = source2['selected']['1d'].indices;

       var d = source2['data'];
       var inds =

       if (inds_in_source2.length == 0) { return; }

       for (i = 0; i < inds_in_source2.length; i++) {
           ind2 = inds_in_source2[i]
           inds.push(d['index'][ind2])
       }

       source1['selected']['1d'].indices = inds
       source1.trigger('change');
   """)
bokeh.io.output_notebook()
bokeh.io.show(column(fig1, data_table, button))

Hitting the select button SHOULD highlight rows 1, 2, 3. But in Bokeh 12.4 only the graph gets updated. The DataTable still has no rows highlighted.

--
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/421feed4-35b1-49e1-8b0d-011a4d7c71bc%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/b7935085-d975-4f4c-be03-e334956b01d5%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
<test_highlight_from_python.py><test_highlight_from_CustomJS.py>

Creating issue in the next few minutes. I am wondering if there is a work-around for this in the meantime (given my own deadlines :slight_smile:

···

On Friday, July 14, 2017 at 5:06:22 PM UTC-7, Bryan Van de ven wrote:

Further info, the reason permuted_indices is [-1, -1, -1] is because “selected_indices” right above is [7, 8, 9] (not [1,2,3]) I expect this is some unforeseen interaction specific to filtered data sources. Definitely make the issue and I will add this information and ping Claire on it

Thanks,

Bryan

On Jul 14, 2017, at 19:02, Bryan Van de ven [email protected] wrote:

Hi,

Thanks for the kind words. After running these examples and a little investigation, there is definitely an issue. The proximate cause is that this line:

    [https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/widgets/tables/data_table.coffee#L115](https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/widgets/tables/data_table.coffee#L115)

is returning [-1, -1, -1] for permuted_indices when the selection is set. Hopefully something simple to fix. Can you make a GitHub issue with these scripts attached? Thanks!

Bryan

PS, FYI for 0.12.6, I modified your callback as follows:

button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""

   source2.selected['1d'].indices = [1,2,3];
   var inds_in_source2 = source2.selected['1d'].indices;
   var d = source2['data'];
   var inds = []
   if (inds_in_source2.length == 0) { return; }
   for (i = 0; i < inds_in_source2.length; i++) {
       ind2 = inds_in_source2[i]
       inds.push(d['index'][ind2])
   }
   source1.selected['1d'].indices = inds
   source1.change.emit()
   source2.properties.selected.change.emit();
   console.log(source2)

“”")

On Jul 14, 2017, at 18:42, Anthony Le [email protected] wrote:

2 things:

1.) The two files have been attached to this message.

2.) Also a heartfelt thank you for looking at this. As a developer myself, I understand the problems of a lot of work and interuptions a lot.

On Friday, July 14, 2017 at 4:22:25 PM UTC-7, Bryan Van de ven wrote:

Apologies, but this is not a complete script that I can just run as-is at the command line. Not trying to be difficult but there’s only a handful of core devs and a great many users. With so many support inquiries every day, trying to deal with things that are incomplete adds up to a substantial burden on a handful of individuals. As I said, if I can run something immediately at the command line I can often immediately offer help, or at least discern where the problem is, so I’m happy to look a close look at anything I can just run “python test.py” on.

Thanks,

Bryan

On Jul 14, 2017, at 17:46, Anthony Le [email protected] wrote:

With pleasure. To troubleshoot things, I am just working on clairetang’s original code describing the problem of filterable CDS:

source2 = ColumnDataSource(filtered_data)

fig1 = figure(plot_width=300, plot_height=300)
fig1.circle(x=‘x’, y=‘y’, size=10, source=source1)

columns = [
TableColumn(field=“y”, title=“Y”),
TableColumn(field=“z”, title=“Text”),
]
data_table = DataTable(source=source2, columns=columns, width=400, height=280)

button = Button(label=“Select”)
button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""
source2[‘selected’][‘1d’].indices =[1,2,3]
var inds_in_source2 = source2[‘selected’][‘1d’].indices;

   var d = source2['data'];
   var inds = []

   if (inds_in_source2.length == 0) { return; }

   for (i = 0; i < inds_in_source2.length; i++) {
       ind2 = inds_in_source2[i]
       inds.push(d['index'][ind2])
   }

   source1['selected']['1d'].indices = inds
   source1.trigger('change');

“”")
bokeh.io.output_notebook()
bokeh.io.show(column(fig1, data_table, button))

Hitting the select button SHOULD highlight rows 1, 2, 3. But in Bokeh 12.4 only the graph gets updated. The DataTable still has no rows highlighted.


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/421feed4-35b1-49e1-8b0d-011a4d7c71bc%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/b7935085-d975-4f4c-be03-e334956b01d5%40continuum.io.

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

<test_highlight_from_python.py><test_highlight_from_CustomJS.py>

Anthony,

The problem only seems to manifest in the presence of filtered data sources, which is not yet in any actual release. Are you specifically trying to use this filtering feature?

Bryan

···

On Jul 14, 2017, at 20:08, Anthony Le <[email protected]> wrote:

Creating issue in the next few minutes. I am wondering if there is a work-around for this in the meantime (given my own deadlines :slight_smile:

On Friday, July 14, 2017 at 5:06:22 PM UTC-7, Bryan Van de ven wrote:
Further info, the reason permuted_indices is [-1, -1, -1] is because "selected_indices" right above is [7, 8, 9] (not [1,2,3]) I expect this is some unforeseen interaction specific to filtered data sources. Definitely make the issue and I will add this information and ping Claire on it

Thanks,

Bryan

> On Jul 14, 2017, at 19:02, Bryan Van de ven <[email protected]> wrote:
>
> Hi,
>
> Thanks for the kind words. After running these examples and a little investigation, there is definitely an issue. The proximate cause is that this line:
>
> https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/widgets/tables/data_table.coffee#L115
>
> is returning [-1, -1, -1] for permuted_indices when the selection is set. Hopefully something simple to fix. Can you make a GitHub issue with these scripts attached? Thanks!
>
> Bryan
>
> PS, FYI for 0.12.6, I modified your callback as follows:
>
>
>
> button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""
> source2.selected['1d'].indices = [1,2,3];
> var inds_in_source2 = source2.selected['1d'].indices;
>
> var d = source2['data'];
> var inds =
>
> if (inds_in_source2.length == 0) { return; }
>
> for (i = 0; i < inds_in_source2.length; i++) {
> ind2 = inds_in_source2[i]
> inds.push(d['index'][ind2])
> }
> source1.selected['1d'].indices = inds
> source1.change.emit()
>
> source2.properties.selected.change.emit();
> console.log(source2)
> """)
>
>> On Jul 14, 2017, at 18:42, Anthony Le <[email protected]> wrote:
>>
>> 2 things:
>>
>> 1.) The two files have been attached to this message.
>> 2.) Also a heartfelt thank you for looking at this. As a developer myself, I understand the problems of a lot of work and interuptions a lot.
>>
>>
>>
>> On Friday, July 14, 2017 at 4:22:25 PM UTC-7, Bryan Van de ven wrote:
>> Apologies, but this is not a complete script that I can just run as-is at the command line. Not trying to be difficult but there's only a handful of core devs and a great many users. With so many support inquiries every day, trying to deal with things that are incomplete adds up to a substantial burden on a handful of individuals. As I said, if I can run something immediately at the command line I can often immediately offer help, or at least discern where the problem is, so I'm happy to look a close look at anything I can just run "python test.py" on.
>>
>> Thanks,
>>
>> Bryan
>>
>>
>>> On Jul 14, 2017, at 17:46, Anthony Le <[email protected]> wrote:
>>>
>>> With pleasure. To troubleshoot things, I am just working on clairetang's original code describing the problem of filterable CDS:
>>>
>>> source2 = ColumnDataSource(filtered_data)
>>>
>>> fig1 = figure(plot_width=300, plot_height=300)
>>> fig1.circle(x='x', y='y', size=10, source=source1)
>>>
>>> columns = [
>>> TableColumn(field="y", title="Y"),
>>> TableColumn(field="z", title="Text"),
>>> ]
>>> data_table = DataTable(source=source2, columns=columns, width=400, height=280)
>>>
>>> button = Button(label="Select")
>>> button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""
>>> source2['selected']['1d'].indices =[1,2,3]
>>> var inds_in_source2 = source2['selected']['1d'].indices;
>>>
>>> var d = source2['data'];
>>> var inds =
>>>
>>> if (inds_in_source2.length == 0) { return; }
>>>
>>> for (i = 0; i < inds_in_source2.length; i++) {
>>> ind2 = inds_in_source2[i]
>>> inds.push(d['index'][ind2])
>>> }
>>>
>>> source1['selected']['1d'].indices = inds
>>> source1.trigger('change');
>>> """)
>>> bokeh.io.output_notebook()
>>> bokeh.io.show(column(fig1, data_table, button))
>>>
>>> Hitting the select button SHOULD highlight rows 1, 2, 3. But in Bokeh 12.4 only the graph gets updated. The DataTable still has no rows highlighted.
>>>
>>> --
>>> 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/421feed4-35b1-49e1-8b0d-011a4d7c71bc%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/b7935085-d975-4f4c-be03-e334956b01d5%40continuum.io.
>> For more options, visit https://groups.google.com/a/continuum.io/d/optout.
>> <test_highlight_from_python.py><test_highlight_from_CustomJS.py>
>

--
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/47438b40-29a4-4c82-b20b-107cf3cb5554%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Bryan,

I was originally looking for a solution similar to what Claire was was proposing but with a heat map. The problem was originally described here:

I realized that for a heat map which requires x, y, and values and unique x,y with each value, I could not adopt the solution as intended.

Instead:

- Try to pre-select rows I think are desirable for each x, y - perhaps pick the largest value.

The selection should show on the data table.

- Use selected indices to populate heat map data source, and display values in heatmap. As selection of the above datatable changes, the values in the heatmap should get updated.

I have been running into a lot of issues just with the first part. At this point, I can trigger preselection within the contex of a static page or notebook as described in the above stackoverflow question. In essence, I try this:

callback = CustomJS (args=dict (source=source), code='''
source['selected']['1d'].indices = {0}
Source.properties.selected.change.emit()
'''.format(selected_index)

However, when I try this approach on the Bokwh server app, still nothing gets selected. My strong suspicion is that when I execute a cell in Jupyter, everything gets computed at the time, and the selected_index gets filled in at that time. When I try to do this on the Bokwh server app, initially there is only an empty list when the above CustomJS is instantiated. I cannot just update and fill in. Am I right?

If that is the case, how do I free dynamically calculated parameters in a CustomJS so that I can trigger selected routes to show?

I am moving on to working on propagating changes in selected rows from a data table to the heatmap and then saving said selection. But I really hope some sort of pointer as to how I can achieve the first part (dynamic selection of rows without clicking on the datatable) could be achieved. Any pointers in this regard from any of the core developers or anyone else would be highly appreciated! Thank you ahead of time!

Hi Anthony,

This bokeh server example might be helpful. I’m not sure this is the best way to achieve what you’re after, but it’s one solution.

In this example, the way you dynamically select rows is to have a second data source which you put the computed row indices into. The bokeh server automatically syncs data sources so when the .data property on the data source changes on the python side, it is reflected on the front end. Clicking button2, “Compute indices”, calls the python function compute_indices which sets .data on source2. At this point, you have to then click on the “Select” button, which calls the CustomJS function which takes the data from source2 and sets the selected indices on source1 which is the data source containing the data for the plots. I don’t think there is a way to set the selected property on the Python side and have it propagate to the JS side, so that’s why the CustomJS might be necessary for now. There is also another detail where the signal that causes the the re-rendering of the plot differs from the one that causes highlighting in the data table (see the comments in the CustomJS below).

from bokeh.plotting import figure, curdoc

from bokeh.models import CustomJS

from bokeh.models.sources import ColumnDataSource

from bokeh.layouts import row, column

from bokeh.models.widgets import DataTable, TableColumn, Button

import random

data = dict(index=list(range(10)), x = list(range(10)), y = list(range(10)), z = [‘some other data’] * 10)

source1 = ColumnDataSource(data)

source2 = ColumnDataSource(dict(computed_indices=[1,2,3]))

fig1 = figure(plot_width=300, plot_height=300)

fig1.circle(x=‘x’, y=‘y’, size=10, source=source1)

columns = [

TableColumn(field=“y”, title=“Y”),

TableColumn(field=“z”, title=“Text”),

]

data_table = DataTable(source=source1, columns=columns, width=400, height=280)

button = Button(label=“Select”)

button.callback = CustomJS(args=dict(source1=source1, source2=source2), code="""

source1[‘selected’][‘1d’].indices = source2[‘data’][‘computed_indices’]

source1.properties.selected.change.emit() //DataTable highlights when the selected property “change” signal is emitted

source1.select.emit() //GlyphRenderer (the circles in this example) re-render when a data source’s “select” signal is emitted

“”")

def compute_indices():

computed_indices = random.sample(list(range(10)), 3)

new_data = dict(computed_indices=computed_indices)

source2.data = new_data

button2 = Button(label=“Compute indices”)

button2.on_click(compute_indices)

curdoc().add_root(row(fig1, data_table, column(button2, button)))

``

Best,

Claire