Datatable does not update properly with change in its data source

I am unable to get the datatable to update correctly with a change in the data source. A reproducible example is below, run with bokeh serve.

When printing I can see that the source has changed, but the table changes to a table with multiple blank rows.

Please let me know if you have any ideas about how to make this work. Thank you in advance.

def make_table_src(df,w,h):

df_src = ColumnDataSource(df)

table_columns = [TableColumn(field = col,title=col) for col in df.columns]

df_table = DataTable(source=df_src, columns=table_columns,width=w,height = h,selectable=True,sortable=True)

return df_src,df_table

outtable_df = pd.DataFrame({’’:‘No Selections Made’})

outtable_df_src,outtable_df_dt =make_table_src(outtable_df,1000,500)

print(outtable_df_src.data)

def change():

b=pd.DataFrame({‘A’:[1,2,3],‘B’:[4,5,6]})

nouttable_df_src,nouttable_df_dt =make_table_src(b,1000,500)

outtable_df_src.data = nouttable_df_src.data

print(outtable_df_src.data)

startButton = Button(label=“Start Test1”)

startButton.on_click(change)

curdoc().add_root(row(outtable_df_dt,startButton))

Hi,

I would like to try and run this to test it directly, but it is not complete. It is missing all imports and any data that would allow it to run. Please always provide a complete minimal example to increase the chance that someone can help you.

Offhand, all I can suggest is that it's definitely a dis-recommended practice to set the .data of CDS from the .data of another CDS. Rather you should set the .data from a plain python dict. The CDS and its .data properties are very heavily instrumented with specialized machinery to allow the auto-synchronization. Every example in the repository and docs follows the patter of setting .data from a plain python data structure and you should follow that as well.

Thanks,

Bryan

···

On Mar 21, 2019, at 3:58 PM, [email protected] wrote:

I am unable to get the datatable to update correctly with a change in the data source. A reproducible example is below, run with bokeh serve.

When printing I can see that the source has changed, but the table changes to a table with multiple blank rows.

Please let me know if you have any ideas about how to make this work. Thank you in advance.

def make_table_src(df,w,h):
    df_src = ColumnDataSource(df)
    table_columns = [TableColumn(field = col,title=col) for col in df.columns]
    df_table = DataTable(source=df_src, columns=table_columns,width=w,height = h,selectable=True,sortable=True)
    return df_src,df_table

outtable_df = pd.DataFrame({'':'No Selections Made'})
outtable_df_src,outtable_df_dt =make_table_src(outtable_df,1000,500)
print(outtable_df_src.data)

def change():
    b=pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})
    nouttable_df_src,nouttable_df_dt =make_table_src(b,1000,500)
    outtable_df_src.data = nouttable_df_src.data
    print(outtable_df_src.data)

startButton = Button(label="Start Test1")
startButton.on_click(change)

curdoc().add_root(row(outtable_df_dt,startButton))

--
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/af58995d-056b-4c35-8400-3e200c1e28b4%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Bryan,

Sorry about that - I’ve attached a fully reproducible example below.

I’ve updated it to show that it works if the existing columns match the columns of the new python dict (i.e. both source and dict have ‘A’,‘B’). It does not work if this is not the case.

Is there any way to get around this problem? I do not know beforehand how many columns I will need or what the names of those columns will be. I was trying to create an “empty” datatable that I could fill once I retrieved that information.

from bokeh.models import ColumnDataSource, Plot, Range1d, Text, TapTool, CustomJS

from bokeh.models.widgets import RangeSlider, Button, DataTable, TableColumn, NumberFormatter, Dropdown, Tabs

import pandas as pd

from bokeh.io import curdoc

from bokeh.layouts import widgetbox, row, column

def make_table_src(df,w,h):

‘’‘Takes in name of csv and outputs bokeh DataTable’’’

df_src = ColumnDataSource(df)

table_columns = [TableColumn(field = col,title=col) for col in df.columns]

df_table = DataTable(source=df_src, columns=table_columns,width=w,height = h,selectable=True,sortable=True) #columns=table_columns

return df_src,df_table

def change1():

example1_src.data = b_dict

def change2():

example2_src.data = b_dict

example1_df = pd.DataFrame({’’:[‘No Selections Made’]})

example1_src, example1_dt = make_table_src(example1_df,1000,500)

example2_df = pd.DataFrame({‘A’:[‘No Selections Made’],‘B’:[’’]}) #has same columns as b

example2_src,example2_dt =make_table_src(example2_df,1000,500)

b_dict = {‘A’:[1,2,3],‘B’:[4,5,6]}

ex1_Button = Button(label=“Change Ex 1”)

ex1_Button.on_click(change1)

ex2_Button = Button(label=“Change Ex 2”)

ex2_Button.on_click(change2)

curdoc().add_root(column(row(example1_dt,ex1_Button),row(example2_dt,ex2_Button)))

···

On Thursday, March 21, 2019 at 5:43:08 PM UTC-7, Bryan Van de ven wrote:

Hi,

I would like to try and run this to test it directly, but it is not complete. It is missing all imports and any data that would allow it to run. Please always provide a complete minimal example to increase the chance that someone can help you.

Offhand, all I can suggest is that it’s definitely a dis-recommended practice to set the .data of CDS from the .data of another CDS. Rather you should set the .data from a plain python dict. The CDS and its .data properties are very heavily instrumented with specialized machinery to allow the auto-synchronization. Every example in the repository and docs follows the patter of setting .data from a plain python data structure and you should follow that as well.

Thanks,

Bryan

On Mar 21, 2019, at 3:58 PM, dw…@cornell.edu wrote:

I am unable to get the datatable to update correctly with a change in the data source. A reproducible example is below, run with bokeh serve.

When printing I can see that the source has changed, but the table changes to a table with multiple blank rows.

Please let me know if you have any ideas about how to make this work. Thank you in advance.

def make_table_src(df,w,h):

df_src = ColumnDataSource(df)
table_columns = [TableColumn(field = col,title=col) for col in df.columns]
df_table = DataTable(source=df_src, columns=table_columns,width=w,height = h,selectable=True,sortable=True)
return df_src,df_table

outtable_df = pd.DataFrame({’’:‘No Selections Made’})

outtable_df_src,outtable_df_dt =make_table_src(outtable_df,1000,500)

print(outtable_df_src.data)

def change():

b=pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})
nouttable_df_src,nouttable_df_dt =make_table_src(b,1000,500)
outtable_df_src.data = nouttable_df_src.data
print(outtable_df_src.data)

startButton = Button(label=“Start Test1”)

startButton.on_click(change)

curdoc().add_root(row(outtable_df_dt,startButton))


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/af58995d-056b-4c35-8400-3e200c1e28b4%40continuum.io.

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

Hi,

What is shown in the DataTable is a function of the DataTable configuration, not just what's in its data source. If the number and names of the columns will be changing, you will have to update the .columns property of the DataTable appropriately.

That's orthogonal to the need to configure .data with a plain dict. There are lots of ways to create the appropriate dict from a DataFrame, or whatever, any time you need it, e.g.

  https://bokeh.pydata.org/en/latest/docs/reference/models/sources.html#bokeh.models.sources.ColumnDataSource.from_df

or by hand.

Thanks,

Bryan

···

On Mar 21, 2019, at 8:35 PM, [email protected] wrote:

Hi Bryan,

Sorry about that - I've attached a fully reproducible example below.

I've updated it to show that it works if the existing columns match the columns of the new python dict (i.e. both source and dict have 'A','B'). It does not work if this is not the case.

Is there any way to get around this problem? I do not know beforehand how many columns I will need or what the names of those columns will be. I was trying to create an "empty" datatable that I could fill once I retrieved that information.

from bokeh.models import ColumnDataSource, Plot, Range1d, Text, TapTool, CustomJS
from bokeh.models.widgets import RangeSlider, Button, DataTable, TableColumn, NumberFormatter, Dropdown, Tabs
import pandas as pd
from bokeh.io import curdoc
from bokeh.layouts import widgetbox, row, column

def make_table_src(df,w,h):
    '''Takes in name of csv and outputs bokeh DataTable'''
    df_src = ColumnDataSource(df)
    table_columns = [TableColumn(field = col,title=col) for col in df.columns]
    df_table = DataTable(source=df_src, columns=table_columns,width=w,height = h,selectable=True,sortable=True) #columns=table_columns

    return df_src,df_table

def change1():
    example1_src.data = b_dict

def change2():
    example2_src.data = b_dict

example1_df = pd.DataFrame({'':['No Selections Made']})
example1_src, example1_dt = make_table_src(example1_df,1000,500)

example2_df = pd.DataFrame({'A':['No Selections Made'],'B':['']}) #has same columns as b
example2_src,example2_dt =make_table_src(example2_df,1000,500)

b_dict = {'A':[1,2,3],'B':[4,5,6]}

ex1_Button = Button(label="Change Ex 1")
ex1_Button.on_click(change1)

ex2_Button = Button(label="Change Ex 2")
ex2_Button.on_click(change2)

curdoc().add_root(column(row(example1_dt,ex1_Button),row(example2_dt,ex2_Button)))

On Thursday, March 21, 2019 at 5:43:08 PM UTC-7, Bryan Van de ven wrote:
Hi,

I would like to try and run this to test it directly, but it is not complete. It is missing all imports and any data that would allow it to run. Please always provide a complete minimal example to increase the chance that someone can help you.

Offhand, all I can suggest is that it's definitely a dis-recommended practice to set the .data of CDS from the .data of another CDS. Rather you should set the .data from a plain python dict. The CDS and its .data properties are very heavily instrumented with specialized machinery to allow the auto-synchronization. Every example in the repository and docs follows the patter of setting .data from a plain python data structure and you should follow that as well.

Thanks,

Bryan

> On Mar 21, 2019, at 3:58 PM, dw...@cornell.edu wrote:
>
> I am unable to get the datatable to update correctly with a change in the data source. A reproducible example is below, run with bokeh serve.
>
> When printing I can see that the source has changed, but the table changes to a table with multiple blank rows.
>
> Please let me know if you have any ideas about how to make this work. Thank you in advance.
>
> def make_table_src(df,w,h):
> df_src = ColumnDataSource(df)
> table_columns = [TableColumn(field = col,title=col) for col in df.columns]
> df_table = DataTable(source=df_src, columns=table_columns,width=w,height = h,selectable=True,sortable=True)
> return df_src,df_table
>
> outtable_df = pd.DataFrame({'':'No Selections Made'})
> outtable_df_src,outtable_df_dt =make_table_src(outtable_df,1000,500)
> print(outtable_df_src.data)
>
> def change():
> b=pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})
> nouttable_df_src,nouttable_df_dt =make_table_src(b,1000,500)
> outtable_df_src.data = nouttable_df_src.data
> print(outtable_df_src.data)
>
> startButton = Button(label="Start Test1")
> startButton.on_click(change)
>
> curdoc().add_root(row(outtable_df_dt,startButton))
>
> --
> 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/af58995d-056b-4c35-8400-3e200c1e28b4%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/2999d2bf-9bef-4dae-8028-bfb8b690d74e%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

I was able to get it to work by changing .columns. Thank you!

···

On Thursday, March 21, 2019 at 9:04:13 PM UTC-7, Bryan Van de ven wrote:

Hi,

What is shown in the DataTable is a function of the DataTable configuration, not just what’s in its data source. If the number and names of the columns will be changing, you will have to update the .columns property of the DataTable appropriately.

That’s orthogonal to the need to configure .data with a plain dict. There are lots of ways to create the appropriate dict from a DataFrame, or whatever, any time you need it, e.g.

    [https://bokeh.pydata.org/en/latest/docs/reference/models/sources.html#bokeh.models.sources.ColumnDataSource.from_df](https://bokeh.pydata.org/en/latest/docs/reference/models/sources.html#bokeh.models.sources.ColumnDataSource.from_df)

or by hand.

Thanks,

Bryan

On Mar 21, 2019, at 8:35 PM, dw…@cornell.edu wrote:

Hi Bryan,

Sorry about that - I’ve attached a fully reproducible example below.

I’ve updated it to show that it works if the existing columns match the columns of the new python dict (i.e. both source and dict have ‘A’,‘B’). It does not work if this is not the case.

Is there any way to get around this problem? I do not know beforehand how many columns I will need or what the names of those columns will be. I was trying to create an “empty” datatable that I could fill once I retrieved that information.

from bokeh.models import ColumnDataSource, Plot, Range1d, Text, TapTool, CustomJS

from bokeh.models.widgets import RangeSlider, Button, DataTable, TableColumn, NumberFormatter, Dropdown, Tabs

import pandas as pd

from bokeh.io import curdoc

from bokeh.layouts import widgetbox, row, column

def make_table_src(df,w,h):

'''Takes in name of csv and outputs bokeh DataTable'''
df_src = ColumnDataSource(df)
table_columns = [TableColumn(field = col,title=col) for col in df.columns]
df_table = DataTable(source=df_src, columns=table_columns,width=w,height = h,selectable=True,sortable=True) #columns=table_columns
return df_src,df_table

def change1():

example1_src.data = b_dict

def change2():

example2_src.data = b_dict

example1_df = pd.DataFrame({’’:[‘No Selections Made’]})

example1_src, example1_dt = make_table_src(example1_df,1000,500)

example2_df = pd.DataFrame({‘A’:[‘No Selections Made’],‘B’:[’’]}) #has same columns as b

example2_src,example2_dt =make_table_src(example2_df,1000,500)

b_dict = {‘A’:[1,2,3],‘B’:[4,5,6]}

ex1_Button = Button(label=“Change Ex 1”)

ex1_Button.on_click(change1)

ex2_Button = Button(label=“Change Ex 2”)

ex2_Button.on_click(change2)

curdoc().add_root(column(row(example1_dt,ex1_Button),row(example2_dt,ex2_Button)))

On Thursday, March 21, 2019 at 5:43:08 PM UTC-7, Bryan Van de ven wrote:

Hi,

I would like to try and run this to test it directly, but it is not complete. It is missing all imports and any data that would allow it to run. Please always provide a complete minimal example to increase the chance that someone can help you.

Offhand, all I can suggest is that it’s definitely a dis-recommended practice to set the .data of CDS from the .data of another CDS. Rather you should set the .data from a plain python dict. The CDS and its .data properties are very heavily instrumented with specialized machinery to allow the auto-synchronization. Every example in the repository and docs follows the patter of setting .data from a plain python data structure and you should follow that as well.

Thanks,

Bryan

On Mar 21, 2019, at 3:58 PM, dw…@cornell.edu wrote:

I am unable to get the datatable to update correctly with a change in the data source. A reproducible example is below, run with bokeh serve.

When printing I can see that the source has changed, but the table changes to a table with multiple blank rows.

Please let me know if you have any ideas about how to make this work. Thank you in advance.

def make_table_src(df,w,h):
df_src = ColumnDataSource(df)
table_columns = [TableColumn(field = col,title=col) for col in df.columns]
df_table = DataTable(source=df_src, columns=table_columns,width=w,height = h,selectable=True,sortable=True)
return df_src,df_table

outtable_df = pd.DataFrame({’’:‘No Selections Made’})
outtable_df_src,outtable_df_dt =make_table_src(outtable_df,1000,500)
print(outtable_df_src.data)

def change():
b=pd.DataFrame({‘A’:[1,2,3],‘B’:[4,5,6]})
nouttable_df_src,nouttable_df_dt =make_table_src(b,1000,500)
outtable_df_src.data = nouttable_df_src.data
print(outtable_df_src.data)

startButton = Button(label=“Start Test1”)
startButton.on_click(change)

curdoc().add_root(row(outtable_df_dt,startButton))


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/af58995d-056b-4c35-8400-3e200c1e28b4%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/2999d2bf-9bef-4dae-8028-bfb8b690d74e%40continuum.io.

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