Filtering DataTables

Hello!

I’m very new to Bokeh, but I have been thoroughly impressed by it thus far.

I’ve perused the docs and this group and I haven’t found an answer to this question, so apologies if it’s already been answered and I missed it.

I was wondering if there is any way to include filtering functionality on a DataTable.

Ideally I’d love to be able to use something like these plugins for SlickGrid as well as have the table filter down for plot points selected by the box select tool.

Is this possible in Bokeh as it exists now?

Thank you,

Liam

Hi Liam,

This is definitely possible, but does require using the bokeh-server. Run the bokeh-server with something like this:

  bokeh-server --dev

And then run this example:

  https://github.com/bokeh/bokeh/blob/master/examples/glyphs/data_tables_server.py

You can see a quick loop of this example in action here:

  https://vine.co/v/OvUJ9iIP5u7

Bryan

···

On Mar 20, 2015, at 2:52 PM, Liam McCartney <[email protected]> wrote:

Hello!

I'm very new to Bokeh, but I have been thoroughly impressed by it thus far.
I've perused the docs and this group and I haven't found an answer to this question, so apologies if it's already been answered and I missed it.

I was wondering if there is any way to include filtering functionality on a DataTable.
Ideally I'd love to be able to use something like these plugins for SlickGrid as well as have the table filter down for plot points selected by the box select tool.

Is this possible in Bokeh as it exists now?

Thank you,

Liam

--
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/bfcbbf1e-a9f6-44d5-863e-f2b12366fea2%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Sorry for such a delayed response, but thank you for your help, Bryan.
Unfortunately using bokeh-server isn’t an option where I am working.

I was able to do what I wanted with some (admittedly hacky) javascript.

Are there any plans to allow for client side filtering in bokehjs?

Thanks,

Liam

···

On Saturday, March 21, 2015 at 4:17:47 PM UTC-4, Bryan Van de ven wrote:

Hi Liam,

This is definitely possible, but does require using the bokeh-server. Run the bokeh-server with something like this:

    bokeh-server --dev

And then run this example:

    [https://github.com/bokeh/bokeh/blob/master/examples/glyphs/data_tables_server.py](https://github.com/bokeh/bokeh/blob/master/examples/glyphs/data_tables_server.py)

You can see a quick loop of this example in action here:

    [https://vine.co/v/OvUJ9iIP5u7](https://vine.co/v/OvUJ9iIP5u7)

Bryan

On Mar 20, 2015, at 2:52 PM, Liam McCartney [email protected] wrote:

Hello!

I’m very new to Bokeh, but I have been thoroughly impressed by it thus far.

I’ve perused the docs and this group and I haven’t found an answer to this question, so apologies if it’s already been answered and I missed it.

I was wondering if there is any way to include filtering functionality on a DataTable.
Ideally I’d love to be able to use something like these plugins for SlickGrid as well as have the table filter down for plot points selected by the box select tool.

Is this possible in Bokeh as it exists now?

Thank you,

Liam


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/bfcbbf1e-a9f6-44d5-863e-f2b12366fea2%40continuum.io.

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

I was able to put something together that filters the DataTable. It uses multiple filter widgets, so the code is a little cumbersome.

This works in a Jupyter notebook: https://gist.github.com/dennisobrien/450d7da20daaba6d39d0

import bokeh.embed
import bokeh.io
import bokeh.models
import bokeh.models.widgets
import bokeh.plotting
import pandas as pd
from pandas_datareader import wb

bokeh.plotting.output_notebook()

df = wb.download(indicator=‘NY.GDP.PCAP.KD’, country=[‘US’, ‘CA’, ‘MX’], start=2005, end=2008)
df = df.reset_index()

source = bokeh.models.ColumnDataSource(df)
original_source = bokeh.models.ColumnDataSource(df)
columns = [
bokeh.models.widgets.TableColumn(field=“country”, title=“Country”),
bokeh.models.widgets.TableColumn(field=“year”, title=“Year”),
bokeh.models.widgets.TableColumn(field=“NY.GDP.PCAP.KD”, title=“NY.GDP.PCAP.KD”),
]
data_table = bokeh.models.widgets.DataTable(source=source, columns=columns)

callback code to be used by all the filter widgets

requires (source, original_source, country_select_obj, year_select_obj, target_object)

combined_callback_code = “”"
var data = source.get(‘data’);
var original_data = original_source.get(‘data’);
var country = country_select_obj.get(‘value’);
console.log("country: " + country);
var year = year_select_obj.get(‘value’);
console.log("year: " + year);

for (var key in original_data) {
data[key] = ;
for (var i = 0; i < original_data[‘country’].length; ++i) {
if ((country === “ALL” || original_data[‘country’][i] === country) &&
(year === “ALL” || original_data[‘year’][i] === year)) {
data[key].push(original_data[key][i]);
}
}
}
target_obj.trigger(‘change’);
source.trigger(‘change’);
“”"

define the filter widgets, without callbacks for now

country_list = [‘ALL’] + df[‘country’].unique().tolist()
country_select = bokeh.models.widgets.Select(title=“Country:”, value=country_list[0], options=country_list)
year_list = [‘ALL’] + df[‘year’].unique().tolist()
year_select = bokeh.models.widgets.Select(title=“Year:”, value=year_list[0], options=year_list)

now define the callback objects now that the filter widgets exist

country_callback = bokeh.models.CustomJS(
args=dict(source=source,
original_source=original_source,
country_select_obj=country_select,
year_select_obj=year_select,
target_obj=data_table),
code=combined_callback_code)

year_callback = bokeh.models.CustomJS(
args=dict(source=source,
original_source=original_source,
country_select_obj=country_select,
year_select_obj=year_select,
target_obj=data_table),
code=combined_callback_code)

finally, connect the callbacks to the filter widgets

country_select.callback = country_callback
year_select.callback = year_callback

p = bokeh.io.vplot(country_select, year_select, data_table)
bokeh.plotting.show§

``

If you have any suggestions to make this simpler I would appreciate it.

thanks,

Dennis

···

On Wednesday, April 8, 2015 at 8:35:50 AM UTC-7, [email protected] wrote:

Sorry for such a delayed response, but thank you for your help, Bryan.
Unfortunately using bokeh-server isn’t an option where I am working.

I was able to do what I wanted with some (admittedly hacky) javascript.

Are there any plans to allow for client side filtering in bokehjs?

Thanks,

Liam

On Saturday, March 21, 2015 at 4:17:47 PM UTC-4, Bryan Van de ven wrote:

Hi Liam,

This is definitely possible, but does require using the bokeh-server. Run the bokeh-server with something like this:

    bokeh-server --dev

And then run this example:

    [https://github.com/bokeh/bokeh/blob/master/examples/glyphs/data_tables_server.py](https://github.com/bokeh/bokeh/blob/master/examples/glyphs/data_tables_server.py)

You can see a quick loop of this example in action here:

    [https://vine.co/v/OvUJ9iIP5u7](https://vine.co/v/OvUJ9iIP5u7)

Bryan

On Mar 20, 2015, at 2:52 PM, Liam McCartney [email protected] wrote:

Hello!

I’m very new to Bokeh, but I have been thoroughly impressed by it thus far.

I’ve perused the docs and this group and I haven’t found an answer to this question, so apologies if it’s already been answered and I missed it.

I was wondering if there is any way to include filtering functionality on a DataTable.
Ideally I’d love to be able to use something like these plugins for SlickGrid as well as have the table filter down for plot points selected by the box select tool.

Is this possible in Bokeh as it exists now?

Thank you,

Liam


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/bfcbbf1e-a9f6-44d5-863e-f2b12366fea2%40continuum.io.

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

For people on bokeh 0.13, the following code should work. Leaving here because this is one of the top google hits

import bokeh.embed
import bokeh.io
import bokeh.models
import bokeh.models.widgets
import bokeh.plotting
import pandas as pd
from pandas_datareader import wb

from bokeh.layouts import gridplot

bokeh.plotting.output_notebook()

df = wb.download(indicator=‘NY.GDP.PCAP.KD’, country=[‘US’, ‘CA’, ‘MX’], start=2005, end=2008)
df = df.reset_index()

source = bokeh.models.ColumnDataSource(df)
original_source = bokeh.models.ColumnDataSource(df)
columns = [
bokeh.models.widgets.TableColumn(field=“country”, title=“Country”),
bokeh.models.widgets.TableColumn(field=“year”, title=“Year”),
bokeh.models.widgets.TableColumn(field=“NY.GDP.PCAP.KD”, title=“NY.GDP.PCAP.KD”),
]
data_table = bokeh.models.widgets.DataTable(source=source, columns=columns)

callback code to be used by all the filter widgets

requires (source, original_source, country_select_obj, year_select_obj, target_object)

combined_callback_code = “”"
var data = source.data;
var original_data = original_source.data;
var country = country_select_obj.value;
console.log("country: " + country);
var year = year_select_obj.value;
console.log("year: " + year);

for (var key in original_data) {
data[key] = ;
for (var i = 0; i < original_data[‘country’].length; ++i) {
if ((country === “ALL” || original_data[‘country’][i] === country) &&
(year === “ALL” || original_data[‘year’][i] === year)) {
data[key].push(original_data[key][i]);
}
}
}
target_obj.change.emit();
source.change.emit();
“”"

define the filter widgets, without callbacks for now

country_list = [‘ALL’] + df[‘country’].unique().tolist()
country_select = bokeh.models.widgets.Select(title=“Country:”, value=country_list[0], options=country_list)
year_list = [‘ALL’] + df[‘year’].unique().tolist()
year_select = bokeh.models.widgets.Select(title=“Year:”, value=year_list[0], options=year_list)

now define the callback objects now that the filter widgets exist

country_callback = bokeh.models.CustomJS(
args=dict(source=source,
original_source=original_source,
country_select_obj=country_select,
year_select_obj=year_select,
target_obj=data_table),
code=combined_callback_code)

year_callback = bokeh.models.CustomJS(
args=dict(source=source,
original_source=original_source,
country_select_obj=country_select,
year_select_obj=year_select,
target_obj=data_table),
code=combined_callback_code)

finally, connect the callbacks to the filter widgets

country_select.callback = country_callback
year_select.callback = year_callback

pa = gridplot([[country_select], [year_select], [data_table]])
show(pa)

``

``

···

On Wednesday, September 23, 2015 at 5:51:32 PM UTC+5:30, Dennis O’Brien wrote:

I was able to put something together that filters the DataTable. It uses multiple filter widgets, so the code is a little cumbersome.

This works in a Jupyter notebook: https://gist.github.com/dennisobrien/450d7da20daaba6d39d0

import bokeh.embed
import bokeh.io
import bokeh.models
import bokeh.models.widgets
import bokeh.plotting
import pandas as pd
from pandas_datareader import wb

bokeh.plotting.output_notebook()

df = wb.download(indicator=‘NY.GDP.PCAP.KD’, country=[‘US’, ‘CA’, ‘MX’], start=2005, end=2008)
df = df.reset_index()

source = bokeh.models.ColumnDataSource(df)
original_source = bokeh.models.ColumnDataSource(df)
columns = [
bokeh.models.widgets.TableColumn(field=“country”, title=“Country”),
bokeh.models.widgets.TableColumn(field=“year”, title=“Year”),
bokeh.models.widgets.TableColumn(field=“NY.GDP.PCAP.KD”, title=“NY.GDP.PCAP.KD”),
]
data_table = bokeh.models.widgets.DataTable(source=source, columns=columns)

callback code to be used by all the filter widgets

requires (source, original_source, country_select_obj, year_select_obj, target_object)

combined_callback_code = “”"
var data = source.get(‘data’);
var original_data = original_source.get(‘data’);
var country = country_select_obj.get(‘value’);
console.log("country: " + country);
var year = year_select_obj.get(‘value’);
console.log("year: " + year);

for (var key in original_data) {
data[key] = ;
for (var i = 0; i < original_data[‘country’].length; ++i) {
if ((country === “ALL” || original_data[‘country’][i] === country) &&
(year === “ALL” || original_data[‘year’][i] === year)) {
data[key].push(original_data[key][i]);
}
}
}
target_obj.trigger(‘change’);
source.trigger(‘change’);
“”"

define the filter widgets, without callbacks for now

country_list = [‘ALL’] + df[‘country’].unique().tolist()
country_select = bokeh.models.widgets.Select(title=“Country:”, value=country_list[0], options=country_list)
year_list = [‘ALL’] + df[‘year’].unique().tolist()
year_select = bokeh.models.widgets.Select(title=“Year:”, value=year_list[0], options=year_list)

now define the callback objects now that the filter widgets exist

country_callback = bokeh.models.CustomJS(
args=dict(source=source,
original_source=original_source,
country_select_obj=country_select,
year_select_obj=year_select,
target_obj=data_table),
code=combined_callback_code)

year_callback = bokeh.models.CustomJS(
args=dict(source=source,
original_source=original_source,
country_select_obj=country_select,
year_select_obj=year_select,
target_obj=data_table),
code=combined_callback_code)

finally, connect the callbacks to the filter widgets

country_select.callback = country_callback
year_select.callback = year_callback

p = bokeh.io.vplot(country_select, year_select, data_table)
bokeh.plotting.show§

``

If you have any suggestions to make this simpler I would appreciate it.

thanks,

Dennis

On Wednesday, April 8, 2015 at 8:35:50 AM UTC-7, [email protected] wrote:

Sorry for such a delayed response, but thank you for your help, Bryan.
Unfortunately using bokeh-server isn’t an option where I am working.

I was able to do what I wanted with some (admittedly hacky) javascript.

Are there any plans to allow for client side filtering in bokehjs?

Thanks,

Liam

On Saturday, March 21, 2015 at 4:17:47 PM UTC-4, Bryan Van de ven wrote:

Hi Liam,

This is definitely possible, but does require using the bokeh-server. Run the bokeh-server with something like this:

    bokeh-server --dev

And then run this example:

    [https://github.com/bokeh/bokeh/blob/master/examples/glyphs/data_tables_server.py](https://github.com/bokeh/bokeh/blob/master/examples/glyphs/data_tables_server.py)

You can see a quick loop of this example in action here:

    [https://vine.co/v/OvUJ9iIP5u7](https://vine.co/v/OvUJ9iIP5u7)

Bryan

On Mar 20, 2015, at 2:52 PM, Liam McCartney [email protected] wrote:

Hello!

I’m very new to Bokeh, but I have been thoroughly impressed by it thus far.

I’ve perused the docs and this group and I haven’t found an answer to this question, so apologies if it’s already been answered and I missed it.

I was wondering if there is any way to include filtering functionality on a DataTable.
Ideally I’d love to be able to use something like these plugins for SlickGrid as well as have the table filter down for plot points selected by the box select tool.

Is this possible in Bokeh as it exists now?

Thank you,

Liam


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/bfcbbf1e-a9f6-44d5-863e-f2b12366fea2%40continuum.io.

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

Hi Pranav,

The dropdown menu has no effect on the table shown below, I am using bokeh 0.13 and update all the packages, and still have no clue how to solve this issue.

Thanks for your help!

Victor

···

On Monday, June 25, 2018 at 4:41:42 PM UTC-7, Pranav Rai wrote:

For people on bokeh 0.13, the following code should work. Leaving here because this is one of the top google hits

import bokeh.embed
import bokeh.io
import bokeh.models
import bokeh.models.widgets
import bokeh.plotting
import pandas as pd
from pandas_datareader import wb

from bokeh.layouts import gridplot

bokeh.plotting.output_notebook()

df = wb.download(indicator=‘NY.GDP.PCAP.KD’, country=[‘US’, ‘CA’, ‘MX’], start=2005, end=2008)
df = df.reset_index()

source = bokeh.models.ColumnDataSource(df)
original_source = bokeh.models.ColumnDataSource(df)
columns = [
bokeh.models.widgets.TableColumn(field=“country”, title=“Country”),
bokeh.models.widgets.TableColumn(field=“year”, title=“Year”),
bokeh.models.widgets.TableColumn(field=“NY.GDP.PCAP.KD”, title=“NY.GDP.PCAP.KD”),
]
data_table = bokeh.models.widgets.DataTable(source=source, columns=columns)

callback code to be used by all the filter widgets

requires (source, original_source, country_select_obj, year_select_obj, target_object)

combined_callback_code = “”"
var data = source.data;
var original_data = original_source.data;
var country = country_select_obj.value;
console.log("country: " + country);
var year = year_select_obj.value;
console.log("year: " + year);

for (var key in original_data) {
data[key] = ;
for (var i = 0; i < original_data[‘country’].length; ++i) {
if ((country === “ALL” || original_data[‘country’][i] === country) &&
(year === “ALL” || original_data[‘year’][i] === year)) {
data[key].push(original_data[key][i]);
}
}
}
target_obj.change.emit();
source.change.emit();
“”"

define the filter widgets, without callbacks for now

country_list = [‘ALL’] + df[‘country’].unique().tolist()
country_select = bokeh.models.widgets.Select(title=“Country:”, value=country_list[0], options=country_list)
year_list = [‘ALL’] + df[‘year’].unique().tolist()
year_select = bokeh.models.widgets.Select(title=“Year:”, value=year_list[0], options=year_list)

now define the callback objects now that the filter widgets exist

country_callback = bokeh.models.CustomJS(
args=dict(source=source,
original_source=original_source,
country_select_obj=country_select,
year_select_obj=year_select,
target_obj=data_table),
code=combined_callback_code)

year_callback = bokeh.models.CustomJS(
args=dict(source=source,
original_source=original_source,
country_select_obj=country_select,
year_select_obj=year_select,
target_obj=data_table),
code=combined_callback_code)

finally, connect the callbacks to the filter widgets

country_select.callback = country_callback
year_select.callback = year_callback

pa = gridplot([[country_select], [year_select], [data_table]])
show(pa)

``

``

On Wednesday, September 23, 2015 at 5:51:32 PM UTC+5:30, Dennis O’Brien wrote:

I was able to put something together that filters the DataTable. It uses multiple filter widgets, so the code is a little cumbersome.

This works in a Jupyter notebook: https://gist.github.com/dennisobrien/450d7da20daaba6d39d0

import bokeh.embed
import bokeh.io
import bokeh.models
import bokeh.models.widgets
import bokeh.plotting
import pandas as pd
from pandas_datareader import wb

bokeh.plotting.output_notebook()

df = wb.download(indicator=‘NY.GDP.PCAP.KD’, country=[‘US’, ‘CA’, ‘MX’], start=2005, end=2008)
df = df.reset_index()

source = bokeh.models.ColumnDataSource(df)
original_source = bokeh.models.ColumnDataSource(df)
columns = [
bokeh.models.widgets.TableColumn(field=“country”, title=“Country”),
bokeh.models.widgets.TableColumn(field=“year”, title=“Year”),
bokeh.models.widgets.TableColumn(field=“NY.GDP.PCAP.KD”, title=“NY.GDP.PCAP.KD”),
]
data_table = bokeh.models.widgets.DataTable(source=source, columns=columns)

callback code to be used by all the filter widgets

requires (source, original_source, country_select_obj, year_select_obj, target_object)

combined_callback_code = “”"
var data = source.get(‘data’);
var original_data = original_source.get(‘data’);
var country = country_select_obj.get(‘value’);
console.log("country: " + country);
var year = year_select_obj.get(‘value’);
console.log("year: " + year);

for (var key in original_data) {
data[key] = ;
for (var i = 0; i < original_data[‘country’].length; ++i) {
if ((country === “ALL” || original_data[‘country’][i] === country) &&
(year === “ALL” || original_data[‘year’][i] === year)) {
data[key].push(original_data[key][i]);
}
}
}
target_obj.trigger(‘change’);
source.trigger(‘change’);
“”"

define the filter widgets, without callbacks for now

country_list = [‘ALL’] + df[‘country’].unique().tolist()
country_select = bokeh.models.widgets.Select(title=“Country:”, value=country_list[0], options=country_list)
year_list = [‘ALL’] + df[‘year’].unique().tolist()
year_select = bokeh.models.widgets.Select(title=“Year:”, value=year_list[0], options=year_list)

now define the callback objects now that the filter widgets exist

country_callback = bokeh.models.CustomJS(
args=dict(source=source,
original_source=original_source,
country_select_obj=country_select,
year_select_obj=year_select,
target_obj=data_table),
code=combined_callback_code)

year_callback = bokeh.models.CustomJS(
args=dict(source=source,
original_source=original_source,
country_select_obj=country_select,
year_select_obj=year_select,
target_obj=data_table),
code=combined_callback_code)

finally, connect the callbacks to the filter widgets

country_select.callback = country_callback
year_select.callback = year_callback

p = bokeh.io.vplot(country_select, year_select, data_table)
bokeh.plotting.show§

``

If you have any suggestions to make this simpler I would appreciate it.

thanks,

Dennis

On Wednesday, April 8, 2015 at 8:35:50 AM UTC-7, [email protected] wrote:

Sorry for such a delayed response, but thank you for your help, Bryan.
Unfortunately using bokeh-server isn’t an option where I am working.

I was able to do what I wanted with some (admittedly hacky) javascript.

Are there any plans to allow for client side filtering in bokehjs?

Thanks,

Liam

On Saturday, March 21, 2015 at 4:17:47 PM UTC-4, Bryan Van de ven wrote:

Hi Liam,

This is definitely possible, but does require using the bokeh-server. Run the bokeh-server with something like this:

    bokeh-server --dev

And then run this example:

    [https://github.com/bokeh/bokeh/blob/master/examples/glyphs/data_tables_server.py](https://github.com/bokeh/bokeh/blob/master/examples/glyphs/data_tables_server.py)

You can see a quick loop of this example in action here:

    [https://vine.co/v/OvUJ9iIP5u7](https://vine.co/v/OvUJ9iIP5u7)

Bryan

On Mar 20, 2015, at 2:52 PM, Liam McCartney [email protected] wrote:

Hello!

I’m very new to Bokeh, but I have been thoroughly impressed by it thus far.

I’ve perused the docs and this group and I haven’t found an answer to this question, so apologies if it’s already been answered and I missed it.

I was wondering if there is any way to include filtering functionality on a DataTable.
Ideally I’d love to be able to use something like these plugins for SlickGrid as well as have the table filter down for plot points selected by the box select tool.

Is this possible in Bokeh as it exists now?

Thank you,

Liam


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/bfcbbf1e-a9f6-44d5-863e-f2b12366fea2%40continuum.io.

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