Make multiple selections in DataTable and plot it

Is there a way to make multiple selections within a “DataTable” for plotting. In the example below it seems that only one row of data at a time can be selected and plotted. I’d like to make multiple selections and have them all plotted on the same graph.

from datetime import date

from random import randint

from bokeh.models import ColumnDataSource

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

import bokeh.layouts as layouts

import bokeh.models.widgets as widgets

from bokeh.io import curdoc

from bokeh.charts import Line

import numpy as np

data = dict(

dates=[date(2014, 3, i + 1) for i in range(10)],

downloads=[randint(0, 100) for i in range(10)],

)

d_source = ColumnDataSource(data)

columns = [

TableColumn(field=“dates”, title=“Date”, formatter=DateFormatter()),

TableColumn(field=“downloads”, title=“Downloads”),

]

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

data_table.row_headers = False

def table_select_callback(attr, old, new):

selected_row = new[‘1d’][‘indices’][0]

download_count = data[‘downloads’][selected_row]

chart_data = np.random.uniform(0, 100, size=download_count)

fig = Line(chart_data, height=250, width=600)

fig.title.text = “Download times - {}”.format(data[‘dates’][selected_row])

root_layout.children[1] = fig

d_source.on_change(‘selected’, table_select_callback)

root_layout = layouts.Column(data_table, widgets.Div(text=‘Select Date’))

curdoc().add_root(root_layout)

You could try holding Shift or Ctrl (Command if Mac) when selecting from your table.

···

On Mon, Jan 30, 2017 at 3:26 PM, [email protected] wrote:

Is there a way to make multiple selections within a “DataTable” for plotting. In the example below it seems that only one row of data at a time can be selected and plotted. I’d like to make multiple selections and have them all plotted on the same graph.

from datetime import date

from random import randint

from bokeh.models import ColumnDataSource

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

import bokeh.layouts as layouts

import bokeh.models.widgets as widgets

from bokeh.io import curdoc

from bokeh.charts import Line

import numpy as np

data = dict(

dates=[date(2014, 3, i + 1) for i in range(10)],

downloads=[randint(0, 100) for i in range(10)],

)

d_source = ColumnDataSource(data)

columns = [

TableColumn(field=“dates”, title=“Date”, formatter=DateFormatter()),

TableColumn(field=“downloads”, title=“Downloads”),

]

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

data_table.row_headers = False

def table_select_callback(attr, old, new):

selected_row = new[‘1d’][‘indices’][0]

download_count = data[‘downloads’][selected_row]

chart_data = np.random.uniform(0, 100, size=download_count)

fig = Line(chart_data, height=250, width=600)

fig.title.text = “Download times - {}”.format(data[‘dates’][selected_row])

root_layout.children[1] = fig

d_source.on_change(‘selected’, table_select_callback)

root_layout = layouts.Column(data_table, widgets.Div(text=‘Select Date’))

curdoc().add_root(root_layout)

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/5e737d1a-14e4-409d-87c3-21b847cb08e5%40continuum.io.

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

Thanks for your response.

It seems I cannot hold Shift or Ctrl when making multiple selections when a callback is made to the “DataTable”.

How do I capture the selected row from the code? Is there a “DataTable.value” that works for DataTable.

···

On Monday, January 30, 2017 at 3:53:46 PM UTC-5, Luyu Wang wrote:

You could try holding Shift or Ctrl (Command if Mac) when selecting from your table.

On Mon, Jan 30, 2017 at 3:26 PM, [email protected] wrote:

Is there a way to make multiple selections within a “DataTable” for plotting. In the example below it seems that only one row of data at a time can be selected and plotted. I’d like to make multiple selections and have them all plotted on the same graph.

from datetime import date

from random import randint

from bokeh.models import ColumnDataSource

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

import bokeh.layouts as layouts

import bokeh.models.widgets as widgets

from bokeh.io import curdoc

from bokeh.charts import Line

import numpy as np

data = dict(

dates=[date(2014, 3, i + 1) for i in range(10)],

downloads=[randint(0, 100) for i in range(10)],

)

d_source = ColumnDataSource(data)

columns = [

TableColumn(field=“dates”, title=“Date”, formatter=DateFormatter()),

TableColumn(field=“downloads”, title=“Downloads”),

]

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

data_table.row_headers = False

def table_select_callback(attr, old, new):

selected_row = new[‘1d’][‘indices’][0]

download_count = data[‘downloads’][selected_row]

chart_data = np.random.uniform(0, 100, size=download_count)

fig = Line(chart_data, height=250, width=600)

fig.title.text = “Download times - {}”.format(data[‘dates’][selected_row])

root_layout.children[1] = fig

d_source.on_change(‘selected’, table_select_callback)

root_layout = layouts.Column(data_table, widgets.Div(text=‘Select Date’))

curdoc().add_root(root_layout)

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/5e737d1a-14e4-409d-87c3-21b847cb08e5%40continuum.io.

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