# Update DataTable content

**URL:** <https://discourse.bokeh.org/t/update-datatable-content/2022>\
**Category:** Community Support\
**Created:** [March 1, 2017, 7:31pm UTC](https://discourse.bokeh.org/t/update-datatable-content/2022 "2017-03-01T19:31:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Krause](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/d/db5fbb/32.png) [@Daniel\_Krause](https://discourse.bokeh.org/u/Daniel_Krause)\
**Post date:** [March 1, 2017, 7:31pm UTC](https://discourse.bokeh.org/t/update-datatable-content/2022/1 "2017-03-01T19:31:33Z")

</div>

Hello,

I am having trouble to update the content of a DataTable. When some user action takes place (e.g. a radio button is clicked) the datatable should update its content accordingly.

Any ideas, why this example code is working not correctly? The table changes only once, no matter how often the buttons are clicked.

from datetime import date  
from random import randint  
from bokeh.client import push\_session  
from bokeh.models import ColumnDataSource  
from bokeh.models.widgets import RadioButtonGroup, DataTable, DateFormatter, TableColumn  
from bokeh.plotting import curdoc  
from bokeh.layouts import layout

# Starting bokeh server from here

import subprocess  
import time  
args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]  
p = subprocess.Popen(args)  
time.sleep(1) # time to wait might be longer on other PC

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

# columns switched

data2 = dict(  
dates=[date(2017, 3, i+1) for i in range(10)],  
downloads=[randint(100, 200) for i in range(10)],  
)  
source2 = ColumnDataSource(data2)

# defining initial CDS and initial table

source = source1  
columns = [TableColumn(field=“dates”, title=“Date”, formatter=DateFormatter()),  
TableColumn(field=“downloads”, title=“Downloads”)]  
data\_table = DataTable(source=source, columns=columns, width=400, height=280)

# callback for RadioButtonGroup

def select\_data(attr, old, new):  
print(‘callback’)  
print(‘RadioButtonGroup - active is button {}’.format(new))  
if new == 0:  
source.data = source1.data  
print(‘Action for button 0’)  
else:  
source.data = source2.data  
print(‘Action for button 1’)

button = RadioButtonGroup(labels=[“Option 0”, “Option 1”], active=0)  
button.on\_change(‘active’, select\_data)

mylayout = layout([[button], [data\_table]])

session = push\_session(curdoc())  
session.show(mylayout)  
session.loop\_until\_closed()

``

 ![](https://discourse-uploads.bokeh.org/original/1X/94adf8f54da3c4400131a5bd9147b319cde0f020.png)

---

<div class="post-metadata">

**Author:** ![Jacques\_Roy](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@Jacques\_Roy](https://discourse.bokeh.org/u/Jacques_Roy)\
**Post date:** [March 1, 2017, 8:06pm UTC](https://discourse.bokeh.org/t/update-datatable-content/2022/2 "2017-03-01T20:06:24Z")

</div>

I’ve done something similar.

It worked when I added: data\_table.update()

> **···**
>
> On Wed, Mar 1, 2017 at 11:31 AM ‘Daniel Krause’ via Bokeh Discussion - Public [bokeh@continuum.io](mailto:bokeh@continuum.io) wrote:
> 
> > Hello,
> 
> > I am having trouble to update the content of a DataTable. When some user action takes place (e.g. a radio button is clicked) the datatable should update its content accordingly.
> 
> > 
> 
> > Any ideas, why this example code is working not correctly? The table changes only once, no matter how often the buttons are clicked.
> 
> > 
> 
> > from datetime import date  
> > from random import randint  
> > from bokeh.client import push\_session  
> > from bokeh.models import ColumnDataSource  
> > from bokeh.models.widgets import RadioButtonGroup, DataTable, DateFormatter, TableColumn  
> > from bokeh.plotting import curdoc  
> > from bokeh.layouts import layout
> > 
> > # Starting bokeh server from here
> > 
> > import subprocess  
> > import time  
> > args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]  
> > p = subprocess.Popen(args)  
> > time.sleep(1) # time to wait might be longer on other PC
> > 
> > data1 = dict(  
> > dates=[date(2014, 3, i+1) for i in range(10)],  
> > downloads=[randint(0, 100) for i in range(10)],  
> > )  
> > source1 = ColumnDataSource(data1)
> > 
> > # columns switched
> > 
> > data2 = dict(  
> > dates=[date(2017, 3, i+1) for i in range(10)],  
> > downloads=[randint(100, 200) for i in range(10)],  
> > )  
> > source2 = ColumnDataSource(data2)
> > 
> > # defining initial CDS and initial table
> > 
> > source = source1  
> > columns = [TableColumn(field=“dates”, title=“Date”, formatter=DateFormatter()),  
> > TableColumn(field=“downloads”, title=“Downloads”)]  
> > data\_table = DataTable(source=source, columns=columns, width=400, height=280)
> > 
> > # callback for RadioButtonGroup
> > 
> > def select\_data(attr, old, new):  
> > print(‘callback’)  
> > print(‘RadioButtonGroup - active is button {}’.format(new))  
> > if new == 0:  
> > source.data = source1.data  
> > print(‘Action for button 0’)  
> > else:  
> > source.data = source2.data  
> > print(‘Action for button 1’)
> > 
> > button = RadioButtonGroup(labels=[“Option 0”, “Option 1”], active=0)  
> > button.on\_change(‘active’, select\_data)
> > 
> > mylayout = layout([[button], [data\_table]])
> > 
> > session = push\_session(curdoc())  
> > session.show(mylayout)  
> > session.loop\_until\_closed()
> 
> > ``
> 
> > 
> 
> > –
> > 
> > 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](mailto:bokeh+unsubscribe@continuum.io).
> > 
> > To post to this group, send email to [bokeh@continuum.io](mailto:bokeh@continuum.io).
> > 
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/fd1ec3d4-43a2-40f2-80c1-77aa1344a959%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/fd1ec3d4-43a2-40f2-80c1-77aa1344a959%40continuum.io?utm_medium=email&utm_source=footer).
> > 
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).

---

<div class="post-metadata">

**Author:** ![Daniel\_Krause](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/d/db5fbb/32.png) [@Daniel\_Krause](https://discourse.bokeh.org/u/Daniel_Krause)\
**Post date:** [March 1, 2017, 8:37pm UTC](https://discourse.bokeh.org/t/update-datatable-content/2022/3 "2017-03-01T20:37:04Z")

</div>

Jacques, thanks for the idea. I changed the callback and added two lines in the end:

# callback for RadioButtonGroup

def select\_data(attr, old, new):  
print(‘callback’)  
print(‘RadioButtonGroup - active is button {}’.format(new))  
if new == 0:  
source.data = source1.data  
print(‘Action for button 0’)  
else:  
source.data = source2.data  
print(‘Action for button 1’)  
global data\_table  
data\_table.update()

``

Unfortunately it did not solve my problem. It still works only ones, then the table is not changing any more.

> **···**
>
> Am Mittwoch, 1. März 2017 21:06:37 UTC+1 schrieb Jacques Roy:
> 
> > I’ve done something similar.
> 
> > It worked when I added: data\_table.update()
> 
> > 
> 
> > On Wed, Mar 1, 2017 at 11:31 AM ‘Daniel Krause’ via Bokeh Discussion - Public [bo...@continuum.io](mailto:bo...@continuum.io) wrote:
> 
> > > Hello,
> 
> > > I am having trouble to update the content of a DataTable. When some user action takes place (e.g. a radio button is clicked) the datatable should update its content accordingly.
> 
> > >
> 
> > > Any ideas, why this example code is working not correctly? The table changes only once, no matter how often the buttons are clicked.
> 
> > >
> 
> > > from datetime import date  
> > > from random import randint  
> > > from bokeh.client import push\_session  
> > > from bokeh.models import ColumnDataSource  
> > > from bokeh.models.widgets import RadioButtonGroup, DataTable, DateFormatter, TableColumn  
> > > from bokeh.plotting import curdoc  
> > > from bokeh.layouts import layout
> > > 
> > > # Starting bokeh server from here
> > > 
> > > import subprocess  
> > > import time  
> > > args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]  
> > > p = subprocess.Popen(args)  
> > > time.sleep(1) # time to wait might be longer on other PC
> > > 
> > > data1 = dict(  
> > > dates=[date(2014, 3, i+1) for i in range(10)],  
> > > downloads=[randint(0, 100) for i in range(10)],  
> > > )  
> > > source1 = ColumnDataSource(data1)
> > > 
> > > # columns switched
> > > 
> > > data2 = dict(  
> > > dates=[date(2017, 3, i+1) for i in range(10)],  
> > > downloads=[randint(100, 200) for i in range(10)],  
> > > )  
> > > source2 = ColumnDataSource(data2)
> > > 
> > > # defining initial CDS and initial table
> > > 
> > > source = source1  
> > > columns = [TableColumn(field=“dates”, title=“Date”, formatter=DateFormatter()),  
> > > TableColumn(field=“downloads”, title=“Downloads”)]  
> > > data\_table = DataTable(source=source, columns=columns, width=400, height=280)
> > > 
> > > # callback for RadioButtonGroup
> > > 
> > > def select\_data(attr, old, new):  
> > > print(‘callback’)  
> > > print(‘RadioButtonGroup - active is button {}’.format(new))  
> > > if new == 0:  
> > > source.data = source1.data  
> > > print(‘Action for button 0’)  
> > > else:  
> > > source.data = source2.data  
> > > print(‘Action for button 1’)
> > > 
> > > button = RadioButtonGroup(labels=[“Option 0”, “Option 1”], active=0)  
> > > button.on\_change(‘active’, select\_data)
> > > 
> > > mylayout = layout([[button], [data\_table]])
> > > 
> > > session = push\_session(curdoc())  
> > > session.show(mylayout)  
> > > session.loop\_until\_closed()
> 
> > > ``
> 
> > >
> 
> > > –
> > > 
> > > 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+un...@continuum.io](mailto:bokeh+un...@continuum.io).
> > > 
> > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).
> > > 
> > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/fd1ec3d4-43a2-40f2-80c1-77aa1344a959%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/fd1ec3d4-43a2-40f2-80c1-77aa1344a959%40continuum.io?utm_medium=email&utm_source=footer).
> > > 
> > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).

---

<div class="post-metadata">

**Author:** ![FredMaster](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/f/ecccb3/32.png) [@FredMaster](https://discourse.bokeh.org/u/FredMaster)\
**Post date:** [March 2, 2017, 3:14pm UTC](https://discourse.bokeh.org/t/update-datatable-content/2022/4 "2017-03-02T15:14:13Z")

</div>

Hi Daniel,

I am also quite new to Bokeh so I maybe wrong.

However, I believe you need to update the source1 and source2 within the select\_data() function.

If I copy

> data1 = dict(  
> dates=[date(2014, 3, i+1) for i in range(10)],  
> downloads=[randint(0, 100) for i in range(10)],  
> )  
> source1 = ColumnDataSource(data1)
> 
> # columns switched
> 
> data2 = dict(  
> dates=[date(2017, 3, i+1) for i in range(10)],  
> downloads=[randint(100, 200) for i in range(10)],  
> )  
> source2 = ColumnDataSource(data2)

into the function it works for me.

Fred

> **···**
>
> Am Mittwoch, 1. März 2017 20:31:33 UTC+1 schrieb Daniel Krause:
> 
> > Hello,
> 
> > I am having trouble to update the content of a DataTable. When some user action takes place (e.g. a radio button is clicked) the datatable should update its content accordingly.
> 
> > 
> 
> > Any ideas, why this example code is working not correctly? The table changes only once, no matter how often the buttons are clicked.
> 
> > 
> 
> > from datetime import date  
> > from random import randint  
> > from bokeh.client import push\_session  
> > from bokeh.models import ColumnDataSource  
> > from bokeh.models.widgets import RadioButtonGroup, DataTable, DateFormatter, TableColumn  
> > from bokeh.plotting import curdoc  
> > from bokeh.layouts import layout
> > 
> > # Starting bokeh server from here
> > 
> > import subprocess  
> > import time  
> > args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]  
> > p = subprocess.Popen(args)  
> > time.sleep(1) # time to wait might be longer on other PC
> > 
> > data1 = dict(  
> > dates=[date(2014, 3, i+1) for i in range(10)],  
> > downloads=[randint(0, 100) for i in range(10)],  
> > )  
> > source1 = ColumnDataSource(data1)
> > 
> > # columns switched
> > 
> > data2 = dict(  
> > dates=[date(2017, 3, i+1) for i in range(10)],  
> > downloads=[randint(100, 200) for i in range(10)],  
> > )  
> > source2 = ColumnDataSource(data2)
> > 
> > # defining initial CDS and initial table
> > 
> > source = source1  
> > columns = [TableColumn(field=“dates”, title=“Date”, formatter=DateFormatter()),  
> > TableColumn(field=“downloads”, title=“Downloads”)]  
> > data\_table = DataTable(source=source, columns=columns, width=400, height=280)
> > 
> > # callback for RadioButtonGroup
> > 
> > def select\_data(attr, old, new):  
> > print(‘callback’)  
> > print(‘RadioButtonGroup - active is button {}’.format(new))  
> > if new == 0:  
> > source.data = source1.data  
> > print(‘Action for button 0’)  
> > else:  
> > source.data = source2.data  
> > print(‘Action for button 1’)
> > 
> > button = RadioButtonGroup(labels=[“Option 0”, “Option 1”], active=0)  
> > button.on\_change(‘active’, select\_data)
> > 
> > mylayout = layout([[button], [data\_table]])
> > 
> > session = push\_session(curdoc())  
> > session.show(mylayout)  
> > session.loop\_until\_closed()
> 
> > ``
> 
> >

---

<div class="post-metadata">

**Author:** ![Daniel\_Krause](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/d/db5fbb/32.png) [@Daniel\_Krause](https://discourse.bokeh.org/u/Daniel_Krause)\
**Post date:** [March 2, 2017, 6:09pm UTC](https://discourse.bokeh.org/t/update-datatable-content/2022/5 "2017-03-02T18:09:13Z")

</div>

Hi Fred,

thanks, that helped a lot. To avoid the same code in two different places I use now separate function to create the column data sources. This function is called once at initialization of the table, and than each time the callback is used.

This is my working final code:

from datetime import date  
from random import randint  
from bokeh.client import push\_session  
from bokeh.models import ColumnDataSource  
from bokeh.models.widgets import RadioButtonGroup, DataTable, DateFormatter, TableColumn  
from bokeh.plotting import curdoc  
from bokeh.layouts import layout

# Starting bokeh server from here

import subprocess  
import time  
args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]  
p = subprocess.Popen(args)  
time.sleep(1) # time to wait might be longer on other PC

def create\_cds():  
‘’‘Create two different column data sources’‘’

```
data1 = dict(dates=[date(2014, 3, i+1) for i in range(10)],
             downloads=[randint(0, 100) for i in range(10)])
source1 = ColumnDataSource(data1)
 
data2 = dict(dates=[date(2017, 3, i+1) for i in range(15)],
             downloads=[randint(100, 200) for i in range(15)])
source2 = ColumnDataSource(data2)

return source1, source2

```

# defining initial CDS and initial table

source1, source2 = create\_cds()  
source = source1  
columns = [TableColumn(field=“dates”, title=“Date”, formatter=DateFormatter()),  
TableColumn(field=“downloads”, title=“Downloads”)]  
data\_table = DataTable(source=source, columns=columns, width=400, height=280)

# callback for RadioButtonGroup

def select\_data(attr, old, new):  
print(‘callback’)  
print(‘RadioButtonGroup - active is button {}’.format(new))  
source1, source2 = create\_cds()

```
if new == 0:
    source.data = source1.data
    print('Action for button 0')
else:
    source.data = source2.data
    print('Action for button 1')
global data_table
data_table.update()

```

button = RadioButtonGroup(labels=[“Option 0”, “Option 1”], active=0)  
button.on\_change(‘active’, select\_data)

mylayout = layout([[button], [data\_table]])

session = push\_session(curdoc())  
session.show(mylayout)  
session.loop\_until\_closed()

``

Daniel

> **···**
>
> Am Donnerstag, 2. März 2017 16:14:14 UTC+1 schrieb FredMaster:
> 
> > Hi Daniel,
> 
> > I am also quite new to Bokeh so I maybe wrong.
> 
> > 
> 
> > However, I believe you need to update the source1 and source2 within the select\_data() function.
> 
> > 
> 
> > If I copy
> > 
> > > data1 = dict(  
> > > dates=[date(2014, 3, i+1) for i in range(10)],  
> > > downloads=[randint(0, 100) for i in range(10)],  
> > > )  
> > > source1 = ColumnDataSource(data1)
> > > 
> > > # columns switched
> > > 
> > > data2 = dict(  
> > > dates=[date(2017, 3, i+1) for i in range(10)],  
> > > downloads=[randint(100, 200) for i in range(10)],  
> > > )  
> > > source2 = ColumnDataSource(data2)
> > 
> > into the function it works for me.
> 
> > 
> 
> > Fred
> 
> > Am Mittwoch, 1. März 2017 20:31:33 UTC+1 schrieb Daniel Krause:
> > 
> > > Hello,
> 
> > > I am having trouble to update the content of a DataTable. When some user action takes place (e.g. a radio button is clicked) the datatable should update its content accordingly.
> 
> > >
> 
> > > Any ideas, why this example code is working not correctly? The table changes only once, no matter how often the buttons are clicked.
> 
> > >
> 
> > > from datetime import date  
> > > from random import randint  
> > > from bokeh.client import push\_session  
> > > from bokeh.models import ColumnDataSource  
> > > from bokeh.models.widgets import RadioButtonGroup, DataTable, DateFormatter, TableColumn  
> > > from bokeh.plotting import curdoc  
> > > from bokeh.layouts import layout
> > > 
> > > # Starting bokeh server from here
> > > 
> > > import subprocess  
> > > import time  
> > > args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]  
> > > p = subprocess.Popen(args)  
> > > time.sleep(1) # time to wait might be longer on other PC
> > > 
> > > data1 = dict(  
> > > dates=[date(2014, 3, i+1) for i in range(10)],  
> > > downloads=[randint(0, 100) for i in range(10)],  
> > > )  
> > > source1 = ColumnDataSource(data1)
> > > 
> > > # columns switched
> > > 
> > > data2 = dict(  
> > > dates=[date(2017, 3, i+1) for i in range(10)],  
> > > downloads=[randint(100, 200) for i in range(10)],  
> > > )  
> > > source2 = ColumnDataSource(data2)
> > > 
> > > # defining initial CDS and initial table
> > > 
> > > source = source1  
> > > columns = [TableColumn(field=“dates”, title=“Date”, formatter=DateFormatter()),  
> > > TableColumn(field=“downloads”, title=“Downloads”)]  
> > > data\_table = DataTable(source=source, columns=columns, width=400, height=280)
> > > 
> > > # callback for RadioButtonGroup
> > > 
> > > def select\_data(attr, old, new):  
> > > print(‘callback’)  
> > > print(‘RadioButtonGroup - active is button {}’.format(new))  
> > > if new == 0:  
> > > source.data = source1.data  
> > > print(‘Action for button 0’)  
> > > else:  
> > > source.data = source2.data  
> > > print(‘Action for button 1’)
> > > 
> > > button = RadioButtonGroup(labels=[“Option 0”, “Option 1”], active=0)  
> > > button.on\_change(‘active’, select\_data)
> > > 
> > > mylayout = layout([[button], [data\_table]])
> > > 
> > > session = push\_session(curdoc())  
> > > session.show(mylayout)  
> > > session.loop\_until\_closed()
> 
> > > ``
> 
> > >

---

<div class="post-metadata">

**Author:** ![dekrion](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dekrion](https://discourse.bokeh.org/u/dekrion)\
**Post date:** [October 1, 2017, 10:19pm UTC](https://discourse.bokeh.org/t/update-datatable-content/2022/6 "2017-10-01T22:19:34Z")

</div>

The code did not work for me with Bokeh 0.12.9 so I changed it a little bit:

from datetime import date

from random import randint

from bokeh.client import push\_session

from bokeh.models import ColumnDataSource

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

from bokeh.plotting import curdoc

from bokeh.layouts import layout

import subprocess

import time

args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]

p = subprocess.Popen(args)

time.sleep(1) # time to wait might be longer on other PC

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

source1 = ColumnDataSource(data1)

data2 = dict(dates = [date(2017, 3, i + 1) for i in range(10)], downloads = [randint(100, 200) for i in range(10)])

source2 = ColumnDataSource(data2)

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

```
       TableColumn(field = "downloads", title = "Downloads")]

```

data\_table = DataTable(source = source1, columns = columns, reorderable = False, width = 400, height = 280)

def select\_data(attr, old, new):

```
global data_table

global data1

global data2

update_data = None

print('RadioButtonGroup - active is button {}'.format(new))

if new == 0:

    data_table.source.data.update(data1)

    print('Action for button 0')

else:

    data_table.source.data.update(data2)

    print('Action for button 1')

```

button = RadioButtonGroup(labels = [“Option 0”, “Option 1”], active = 0)

button.on\_change(‘active’, select\_data)

mylayout = layout([[button], [data\_table]])

session = push\_session(curdoc())

session.show(mylayout)

session.loop\_until\_closed()

``

> **···**
>
> On Thursday, March 2, 2017 at 7:09:14 PM UTC+1, Daniel Krause wrote:
> 
> > Hi Fred,
> 
> > thanks, that helped a lot. To avoid the same code in two different places I use now separate function to create the column data sources. This function is called once at initialization of the table, and than each time the callback is used.
> 
> > 
> 
> > This is my working final code:
> 
> > from datetime import date  
> > from random import randint  
> > from bokeh.client import push\_session  
> > from bokeh.models import ColumnDataSource  
> > from bokeh.models.widgets import RadioButtonGroup, DataTable, DateFormatter, TableColumn  
> > from bokeh.plotting import curdoc  
> > from bokeh.layouts import layout
> > 
> > # Starting bokeh server from here
> > 
> > import subprocess  
> > import time  
> > args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]  
> > p = subprocess.Popen(args)  
> > time.sleep(1) # time to wait might be longer on other PC
> > 
> > def create\_cds():  
> > ‘’‘Create two different column data sources’‘’
> > 
> > ```
> > data1 = dict(dates=[date(2014, 3, i+1) for i in range(10)],
> > downloads=[randint(0, 100) for i in range(10)])
> > source1 = ColumnDataSource(data1)
> >  
> > data2 = dict(dates=[date(2017, 3, i+1) for i in range(15)],
> > downloads=[randint(100, 200) for i in range(15)])
> > source2 = ColumnDataSource(data2)
> > 
> > return source1, source2
> > 
> > ```
> > 
> > # defining initial CDS and initial table
> > 
> > source1, source2 = create\_cds()  
> > source = source1  
> > columns = [TableColumn(field=“dates”, title=“Date”, formatter=DateFormatter()),  
> > TableColumn(field=“downloads”, title=“Downloads”)]  
> > data\_table = DataTable(source=source, columns=columns, width=400, height=280)
> > 
> > # callback for RadioButtonGroup
> > 
> > def select\_data(attr, old, new):  
> > print(‘callback’)  
> > print(‘RadioButtonGroup - active is button {}’.format(new))  
> > source1, source2 = create\_cds()
> > 
> > ```
> > if new == 0:
> > source.data = source1.data
> > print('Action for button 0')
> > else:
> > source.data = source2.data
> > print('Action for button 1')
> > global data_table
> > data_table.update()
> > 
> > ```
> > 
> > button = RadioButtonGroup(labels=[“Option 0”, “Option 1”], active=0)  
> > button.on\_change(‘active’, select\_data)
> > 
> > mylayout = layout([[button], [data\_table]])
> > 
> > session = push\_session(curdoc())  
> > session.show(mylayout)  
> > session.loop\_until\_closed()
> 
> > ``
> 
> > 
> 
> > Daniel
> 
> > Am Donnerstag, 2. März 2017 16:14:14 UTC+1 schrieb FredMaster:
> > 
> > > Hi Daniel,
> 
> > > I am also quite new to Bokeh so I maybe wrong.
> 
> > >
> 
> > > However, I believe you need to update the source1 and source2 within the select\_data() function.
> 
> > >
> 
> > > If I copy
> > > 
> > > > data1 = dict(  
> > > > dates=[date(2014, 3, i+1) for i in range(10)],  
> > > > downloads=[randint(0, 100) for i in range(10)],  
> > > > )  
> > > > source1 = ColumnDataSource(data1)
> > > > 
> > > > # columns switched
> > > > 
> > > > data2 = dict(  
> > > > dates=[date(2017, 3, i+1) for i in range(10)],  
> > > > downloads=[randint(100, 200) for i in range(10)],  
> > > > )  
> > > > source2 = ColumnDataSource(data2)
> > > 
> > > into the function it works for me.
> 
> > >
> 
> > > Fred
> 
> > > Am Mittwoch, 1. März 2017 20:31:33 UTC+1 schrieb Daniel Krause:
> > > 
> > > > Hello,
> 
> > > > I am having trouble to update the content of a DataTable. When some user action takes place (e.g. a radio button is clicked) the datatable should update its content accordingly.
> 
> > > >
> 
> > > > Any ideas, why this example code is working not correctly? The table changes only once, no matter how often the buttons are clicked.
> 
> > > >
> 
> > > > from datetime import date  
> > > > from random import randint  
> > > > from bokeh.client import push\_session  
> > > > from bokeh.models import ColumnDataSource  
> > > > from bokeh.models.widgets import RadioButtonGroup, DataTable, DateFormatter, TableColumn  
> > > > from bokeh.plotting import curdoc  
> > > > from bokeh.layouts import layout
> > > > 
> > > > # Starting bokeh server from here
> > > > 
> > > > import subprocess  
> > > > import time  
> > > > args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]  
> > > > p = subprocess.Popen(args)  
> > > > time.sleep(1) # time to wait might be longer on other PC
> > > > 
> > > > data1 = dict(  
> > > > dates=[date(2014, 3, i+1) for i in range(10)],  
> > > > downloads=[randint(0, 100) for i in range(10)],  
> > > > )  
> > > > source1 = ColumnDataSource(data1)
> > > > 
> > > > # columns switched
> > > > 
> > > > data2 = dict(  
> > > > dates=[date(2017, 3, i+1) for i in range(10)],  
> > > > downloads=[randint(100, 200) for i in range(10)],  
> > > > )  
> > > > source2 = ColumnDataSource(data2)
> > > > 
> > > > # defining initial CDS and initial table
> > > > 
> > > > source = source1  
> > > > columns = [TableColumn(field=“dates”, title=“Date”, formatter=DateFormatter()),  
> > > > TableColumn(field=“downloads”, title=“Downloads”)]  
> > > > data\_table = DataTable(source=source, columns=columns, width=400, height=280)
> > > > 
> > > > # callback for RadioButtonGroup
> > > > 
> > > > def select\_data(attr, old, new):  
> > > > print(‘callback’)  
> > > > print(‘RadioButtonGroup - active is button {}’.format(new))  
> > > > if new == 0:  
> > > > source.data = source1.data  
> > > > print(‘Action for button 0’)  
> > > > else:  
> > > > source.data = source2.data  
> > > > print(‘Action for button 1’)
> > > > 
> > > > button = RadioButtonGroup(labels=[“Option 0”, “Option 1”], active=0)  
> > > > button.on\_change(‘active’, select\_data)
> > > > 
> > > > mylayout = layout([[button], [data\_table]])
> > > > 
> > > > session = push\_session(curdoc())  
> > > > session.show(mylayout)  
> > > > session.loop\_until\_closed()
> 
> > > > ``
> 
> > > >

---

<div class="post-metadata">

**Author:** ![system](https://discourse-uploads.bokeh.org/original/2X/1/14eb24f9e10e4e9b78e3f10f66c04ffa96446e5a.svg) [@system](https://discourse.bokeh.org/u/system)\
**Post date:** [July 21, 2021, 9:11pm UTC](https://discourse.bokeh.org/t/update-datatable-content/2022/7 "2021-07-21T21:11:23Z")

</div>


