☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

How can I programmatically select rows in a table?

Community Support
Jim_Sharpe
Jim_Sharpe

I’m trying to figure out how to select various rows in a Table programmatically. The attached notebook is a small example that I thought might work based on the documentation for the selected attr for a DataSource but unfortunately it doesn’t. (I tried both 0d and 1d thinking that might be the problem but neither seemed to do anything, and since I wanted entire rows selected it didn’t seem like 2d would apply).

I’ve looked everywhere I can think of for an example of how to do this or additional documentation but have come up short. Could someone please describe the correct way to specify which rows in a table should be selected?

table_selection_test.ipynb (13 KB)

⌁   Link to post
Schaun_Wheeler
Schaun_Wheeler

Does anyone have any ideas on this? I have a very similar need.

···

On Friday, February 12, 2016 at 1:12:17 PM UTC-5, Jim Sharpe wrote:

I’m trying to figure out how to select various rows in a Table programmatically. The attached notebook is a small example that I thought might work based on the documentation for the selected attr for a DataSource but unfortunately it doesn’t. (I tried both 0d and 1d thinking that might be the problem but neither seemed to do anything, and since I wanted entire rows selected it didn’t seem like 2d would apply).

I’ve looked everywhere I can think of for an example of how to do this or additional documentation but have come up short. Could someone please describe the correct way to specify which rows in a table should be selected?

⌁   Link to post
Dennis_O_Brien
Dennis_O_Brien

Hi Jim,

I don’t have any help for you unfortunately, but I’m interested in the problem. I looked at the notebook you provided. Does that method of setting the selected property of the datasource work for other chart types? If so, maybe the events aren’t propagating in data_table.coffee they way they do in other objects?

For others, here’s the code from the notebook Jim attached:

import bokeh

from bokeh.plotting import figure, output_notebook, show

from bokeh.models import DataTable, ColumnDataSource, TableColumn

from bokeh.io import push_notebook

import pandas as pd

print(‘bokeh version: %s’ % bokeh.version)

output_notebook()

df = pd.DataFrame( {‘AAA’ : [4,5,6,7], ‘BBB’ : [10,20,30,40],‘CCC’ : [100,50,-30,-50]})

data = df.to_dict(orient=‘list’)

tableSource = ColumnDataSource(df)

columns = [TableColumn(field=“AAA”, title=“AAA”),

TableColumn(field=“BBB”, title=“BBB”),

TableColumn(field=“CCC”, title=“CCC”)]

bokehTable = DataTable(columns=columns, source=tableSource,

editable=False, fit_columns=True, height=300,

row_headers=True, selectable=True, sortable=True)

tableSource.selected = {‘1d’:{‘True’:(0,1)}}

show(bokehTable)

I looked through the examples for anything similar to this but didn’t find anything. Maybe others will have ideas.

cheers,

Dennis

···

On Wed, Feb 17, 2016 at 6:27 AM Schaun Wheeler schaun.wheeler@gmail.com wrote:

Does anyone have any ideas on this? I have a very similar need.

On Friday, February 12, 2016 at 1:12:17 PM UTC-5, Jim Sharpe wrote:

I’m trying to figure out how to select various rows in a Table programmatically. The attached notebook is a small example that I thought might work based on the documentation for the selected attr for a DataSource but unfortunately it doesn’t. (I tried both 0d and 1d thinking that might be the problem but neither seemed to do anything, and since I wanted entire rows selected it didn’t seem like 2d would apply).

I’ve looked everywhere I can think of for an example of how to do this or additional documentation but have come up short. Could someone please describe the correct way to specify which rows in a table should be selected?

–

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+unsubscribe@continuum.io.

To post to this group, send email to bokeh@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/58f8228d-7b91-4edd-b39a-4692bbb127fe%40continuum.io.

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

⌁   Link to post
Jim_Sharpe
Jim_Sharpe

Hi Dennis,

I looked around a bit to see how selection is handled with the different chart type and found this example (scroll down to the Selected and Unselected Glyphs section). On the surface it seems like that kind of approach might also work for tables if there were some way to tell a table to render a row differently (i.e. selected). Obviously the table can do that since the rows display differently when you click on them. But It’s not obvious to me how to trigger that rendering behavior externally.

···

On Sunday, February 28, 2016 at 10:53:43 PM UTC-7, Dennis O’Brien wrote:

Hi Jim,

I don’t have any help for you unfortunately, but I’m interested in the problem. I looked at the notebook you provided. Does that method of setting the selected property of the datasource work for other chart types? If so, maybe the events aren’t propagating in data_table.coffee they way they do in other objects?

⌁   Link to post
Top_Cockatiel
Top_Cockatiel

I was just trying to do this. I couldn’t figure how to get anywhere with Jim’s suggestion, and the solution offered here Redirecting to Google Groups didn’t trigger a visible selection.

I think this would be a useful feature, as I’ve found that DataTable selections are useful to set document state parameters and trigger events. Having the default parameter rows visibly selected on load would the document more readable, and make it possible to incrementally change the parameters from their default state (rather than having them reset when the first selection is made).

···

On Monday, February 29, 2016 at 7:36:30 AM UTC-8, Jim Sharpe wrote:

Hi Dennis,

I looked around a bit to see how selection is handled with the different chart type and found this example (scroll down to the Selected and Unselected Glyphs section). On the surface it seems like that kind of approach might also work for tables if there were some way to tell a table to render a row differently (i.e. selected). Obviously the table can do that since the rows display differently when you click on them. But It’s not obvious to me how to trigger that rendering behavior externally.

On Sunday, February 28, 2016 at 10:53:43 PM UTC-7, Dennis O’Brien wrote:

Hi Jim,

I don’t have any help for you unfortunately, but I’m interested in the problem. I looked at the notebook you provided. Does that method of setting the selected property of the datasource work for other chart types? If so, maybe the events aren’t propagating in data_table.coffee they way they do in other objects?

⌁   Link to post
Bryan
Bryan

SlickGrid also has APIs of its own for scrolling, they are not currently exposed via any Bokeh methods, but but they could be used from a CustomJS callback:

Slick.Grid · 6pac/SlickGrid Wiki · GitHub

Regarding, selections, since this is an old pot that has been revived, it should be mentioned that the "0d", "1d" syntax is long-deprecated (and has only been read only for that time) and will be removed in the next few releases. To set a selection on a table, update the selection on the data source that drives it: source.selected.indices = [...]

⌁   Link to post

End of archived discussion · Replies are disabled