Update widget table with new values via stream

I am not sure what is missing and am new to Bokeh. I have a parsed broadcast message that I would like to display inside a table widget. The table widget needs to be updated with new data every 3900ms. Through printf’s I can see that the call back is called and an update is stored in the dictionary but not streamed or displayed. Any guidance would be truly appreciated. Thank you in advance.
Code “”""

import Broadcast

from bokeh.io import curdoc

from bokeh.models import ColumnDataSource

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

source =ColumnDataSource(dict(NAME=,

ID=,

S1=,

S2=,

S3=,

ONLINE=,

IPConn=))

data_table = DataTable(source=source,width=1000, height=280)

def update_data():

data,peername=Broadcast.send(6*1024)

NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)

data = dict(

NAME=[NAME],

ID=[ID],

S1=[S1],

S2=[S2],

S3=[S3],

ONLINE=[ONLINE],

IPConn=[peername]

)

print data

source.stream(data,3900)

curdoc().add_root(data_table)

curdoc().add_periodic_callback(update_data, 3900)

Hi,

Two things. I'm not sure if you just omitted them for brevity, or if you actually don't have them, but you need to configure the data table columns explicitly. See e.g.,

  https://github.com/bokeh/bokeh/blob/master/examples/models/data_tables.py

However, there is also a bug. DataTable is the only widget that is connected to, or responds to a data source. Unfortunately, when streaming support was added, we forgot to add the necessary event handling plumbing to DataTable to make it respond. Fortunately it should just be a one-line trivial fix to apply here:

  https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/widgets/data_table.coffee#L100-L106

I've made an issue you can track here:

  DataTable not wired up to respond to streaming patching · Issue #5732 · bokeh/bokeh · GitHub

This will be fixed in the 0.12.5 release, however, I should be able to have a "dev build" out much sooner (today or tomorrow) that you can install and use. Otherwise, the only option currently is to set .data in the normal, non-streaming way.

Thanks,

Bryan

···

On Jan 14, 2017, at 2:07 AM, [email protected] wrote:

from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn

source =ColumnDataSource(dict(NAME=,
            ID=,
            S1=,
            S2=,
            S3=,
            ONLINE=,
            IPConn=))

data_table = DataTable(source=source,width=1000, height=280)

def update_data():
    data,peername=Broadcast.send(6*1024)
    NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)
    data = dict(
            NAME=[NAME],
            ID=[ID],
            S1=[S1],
            S2=[S2],
            S3=[S3],
            ONLINE=[ONLINE],
            IPConn=[peername]
        )
    print data

    source.stream(data,3900)
curdoc().add_root(data_table)
curdoc().add_periodic_callback(update_data, 3900)

There's one other caveat. DataTables need an index column. If you don't provide one, the BokehJS implementation will synthesize one. But this complicates streaming, since you have to update all columns, and now there is a new one you didn't add yourself. Basically, for now, the best advice is to maintain the index column yourself. With the PR I am about to merge, this code works:

    from random import random
    from bokeh.io import curdoc
    from bokeh.models import ColumnDataSource
    from bokeh.models.widgets import DataTable, DateFormatter, TableColumn, StringEditor, IntEditor, NumberEditor

    source =ColumnDataSource(dict(index=[0], NAME=["bar"], ID=[1], S1=[2]))

    data_table = DataTable(source=source, width=1000, height=280, columns=[
        TableColumn(field="NAME", title="Name", editor=StringEditor()),
        TableColumn(field="ID", title="ID", editor=IntEditor()),
        TableColumn(field="S1", title="s1", editor=NumberEditor())
    ])

    i = 0

    def update_data():
        global i
        NAME, ID, S1 = "foo", i, random()
        i += 1

        data = dict(index=[i], NAME=[NAME], ID=[ID], S1=[S1])
        print (data)
        source.stream(data, 500)

    curdoc().add_root(data_table)
    curdoc().add_periodic_callback(update_data, 500)

Thanks,

Bryan

···

On Jan 14, 2017, at 10:31 AM, Bryan Van de Ven <[email protected]> wrote:

Hi,

Two things. I'm not sure if you just omitted them for brevity, or if you actually don't have them, but you need to configure the data table columns explicitly. See e.g.,

  https://github.com/bokeh/bokeh/blob/master/examples/models/data_tables.py

However, there is also a bug. DataTable is the only widget that is connected to, or responds to a data source. Unfortunately, when streaming support was added, we forgot to add the necessary event handling plumbing to DataTable to make it respond. Fortunately it should just be a one-line trivial fix to apply here:

  https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/widgets/data_table.coffee#L100-L106

I've made an issue you can track here:

  DataTable not wired up to respond to streaming patching · Issue #5732 · bokeh/bokeh · GitHub

This will be fixed in the 0.12.5 release, however, I should be able to have a "dev build" out much sooner (today or tomorrow) that you can install and use. Otherwise, the only option currently is to set .data in the normal, non-streaming way.

Thanks,

Bryan

On Jan 14, 2017, at 2:07 AM, [email protected] wrote:

from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn

source =ColumnDataSource(dict(NAME=,
           ID=,
           S1=,
           S2=,
           S3=,
           ONLINE=,
           IPConn=))

data_table = DataTable(source=source,width=1000, height=280)

def update_data():
   data,peername=Broadcast.send(6*1024)
   NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)
   data = dict(
           NAME=[NAME],
           ID=[ID],
           S1=[S1],
           S2=[S2],
           S3=[S3],
           ONLINE=[ONLINE],
           IPConn=[peername]
       )
   print data

   source.stream(data,3900)
curdoc().add_root(data_table)
curdoc().add_periodic_callback(update_data, 3900)

Thank you for the quick response. I would love to try out dev as refreshing a webpage feels very tacky. It was pretty late last night code that should be posted was as follow:
import Broadcast

from bokeh.io import output_file, show

from bokeh.plotting import figure , curdoc

from bokeh.layouts import widgetbox

from bokeh.models import ColumnDataSource,Button,CustomJS

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

from bokeh.client import push_session

#output_file(“Device Status.html”)

data,peername=Broadcast.send(6*1024)

NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)

data = dict(

NAME=[NAME],

ID=[ID],

S1=[S1],

S2=[S2],

S3=[S3],

ONLINE=[ONLINE],

IPConn=[peername]

)

source = ColumnDataSource(data)

columns = [

TableColumn(field=“NAME”, title=“Device Name”, width=500),

TableColumn(field=“ID”, title=“Device ID”, width=300),

TableColumn(field=“S1”, title=“S1”, width=700),

TableColumn(field=“S2”, title=“S2”, width=700),

TableColumn(field=“IPConn”, title=“IP Connection”, width=700),

TableColumn(field=“S3”, title=“S3”, width=1500)

]

data_table = DataTable(source=source, columns=columns,width=1000, height=280)

def update():

data,peername=Broadcast.send(6*1024)

NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)

data = dict(

NAME=[NAME],

ID=[ID],

S1=[S1],

S2=[S2],

S3=[S3],

ONLINE=[ONLINE],

IPConn=[peername]

)

return data

data=update()

source.data.update(data)

curdoc().add_root(data_table,columns)

curdoc().add_periodic_callback(update, 3900)

···

On Saturday, January 14, 2017 at 5:42:54 AM UTC-8, [email protected] wrote:

I am not sure what is missing and am new to Bokeh. I have a parsed broadcast message that I would like to display inside a table widget. The table widget needs to be updated with new data every 3900ms. Through printf’s I can see that the call back is called and an update is stored in the dictionary but not streamed or displayed. Any guidance would be truly appreciated. Thank you in advance.
Code “”“”

import Broadcast

from bokeh.io import curdoc

from bokeh.models import ColumnDataSource

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

source =ColumnDataSource(dict(NAME=,

ID=,

S1=,

S2=,

S3=,

ONLINE=,

IPConn=))

data_table = DataTable(source=source,width=1000, height=280)

def update_data():

data,peername=Broadcast.send(6*1024)

NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)

data = dict(

NAME=[NAME],

ID=[ID],

S1=[S1],

S2=[S2],

S3=[S3],

ONLINE=[ONLINE],

IPConn=[peername]

)

print data

source.stream(data,3900)

curdoc().add_root(data_table)

curdoc().add_periodic_callback(update_data, 3900)

Hi Bryan,

Silly question how do I test the commit you pushed to master? Do I have to re-build bokeh? What is the timeline for 0.12.5?

Regards,

···

On Saturday, January 14, 2017 at 6:18:32 PM UTC-8, [email protected] wrote:

Thank you for the quick response. I would love to try out dev as refreshing a webpage feels very tacky. It was pretty late last night code that should be posted was as follow:
import Broadcast

from bokeh.io import output_file, show

from bokeh.plotting import figure , curdoc

from bokeh.layouts import widgetbox

from bokeh.models import ColumnDataSource,Button,CustomJS

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

from bokeh.client import push_session

#output_file(“Device Status.html”)

data,peername=Broadcast.send(6*1024)

NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)

data = dict(

NAME=[NAME],

ID=[ID],

S1=[S1],

S2=[S2],

S3=[S3],

ONLINE=[ONLINE],

IPConn=[peername]

)

source = ColumnDataSource(data)

columns = [

TableColumn(field=“NAME”, title=“Device Name”, width=500),

TableColumn(field=“ID”, title=“Device ID”, width=300),

TableColumn(field=“S1”, title=“S1”, width=700),

TableColumn(field=“S2”, title=“S2”, width=700),

TableColumn(field=“IPConn”, title=“IP Connection”, width=700),

TableColumn(field=“S3”, title=“S3”, width=1500)

]

data_table = DataTable(source=source, columns=columns,width=1000, height=280)

def update():

data,peername=Broadcast.send(6*1024)

NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)

data = dict(

NAME=[NAME],

ID=[ID],

S1=[S1],

S2=[S2],

S3=[S3],

ONLINE=[ONLINE],

IPConn=[peername]

)

return data

data=update()

source.data.update(data)

curdoc().add_root(data_table,columns)

curdoc().add_periodic_callback(update, 3900)

On Saturday, January 14, 2017 at 5:42:54 AM UTC-8, [email protected] wrote:

I am not sure what is missing and am new to Bokeh. I have a parsed broadcast message that I would like to display inside a table widget. The table widget needs to be updated with new data every 3900ms. Through printf’s I can see that the call back is called and an update is stored in the dictionary but not streamed or displayed. Any guidance would be truly appreciated. Thank you in advance.
Code “”“”

import Broadcast

from bokeh.io import curdoc

from bokeh.models import ColumnDataSource

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

source =ColumnDataSource(dict(NAME=,

ID=,

S1=,

S2=,

S3=,

ONLINE=,

IPConn=))

data_table = DataTable(source=source,width=1000, height=280)

def update_data():

data,peername=Broadcast.send(6*1024)

NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)

data = dict(

NAME=[NAME],

ID=[ID],

S1=[S1],

S2=[S2],

S3=[S3],

ONLINE=[ONLINE],

IPConn=[peername]

)

print data

source.stream(data,3900)

curdoc().add_root(data_table)

curdoc().add_periodic_callback(update_data, 3900)

Hi,

Not a silly question. The instructions for installing "dev builds" are here:

  <no title> — Bokeh 3.3.2 Documentation

However, we had some fires crop up on our build/CI over the weekend, that are still getting sorted out, so I have not had a chance to make a dev build yet. Currently you would need to clone the repo and build from scratch. But I will hopefully be able to deploy a dev build by tomorrow.

Thank,

Bryan

···

On Jan 15, 2017, at 6:03 PM, [email protected] wrote:

Hi Bryan,

Silly question how do I test the commit you pushed to master? Do I have to re-build bokeh? What is the timeline for 0.12.5?

Regards,

On Saturday, January 14, 2017 at 6:18:32 PM UTC-8, ders...@gmail.com wrote:
Thank you for the quick response. I would love to try out dev as refreshing a webpage feels very tacky. It was pretty late last night code that should be posted was as follow:
import Broadcast

from bokeh.io import output_file, show
from bokeh.plotting import figure , curdoc
from bokeh.layouts import widgetbox
from bokeh.models import ColumnDataSource,Button,CustomJS
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn
from bokeh.client import push_session

#output_file("Device Status.html")
data,peername=Broadcast.send(6*1024)
NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)
data = dict(
            NAME=[NAME],
            ID=[ID],
            S1=[S1],
            S2=[S2],
            S3=[S3],
            ONLINE=[ONLINE],
            IPConn=[peername]
        )
source = ColumnDataSource(data)

columns = [
        TableColumn(field="NAME", title="Device Name", width=500),
        TableColumn(field="ID", title="Device ID", width=300),
        TableColumn(field="S1", title="S1", width=700),
        TableColumn(field="S2", title="S2", width=700),
        TableColumn(field="IPConn", title="IP Connection", width=700),
        TableColumn(field="S3", title="S3", width=1500)
    ]

data_table = DataTable(source=source, columns=columns,width=1000, height=280)
def update():
    data,peername=Broadcast.send(6*1024)
    NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)
    data = dict(
                NAME=[NAME],
                ID=[ID],
                S1=[S1],
                S2=[S2],
                S3=[S3],
                ONLINE=[ONLINE],
                IPConn=[peername]
        )
    return data

data=update()

source.data.update(data)
    
curdoc().add_root(data_table,columns)
curdoc().add_periodic_callback(update, 3900)

On Saturday, January 14, 2017 at 5:42:54 AM UTC-8, ders...@gmail.com wrote:
I am not sure what is missing and am new to Bokeh. I have a parsed broadcast message that I would like to display inside a table widget. The table widget needs to be updated with new data every 3900ms. Through printf's I can see that the call back is called and an update is stored in the dictionary but not streamed or displayed. Any guidance would be truly appreciated. Thank you in advance.
Code """"

import Broadcast

from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn

source =ColumnDataSource(dict(NAME=,
            ID=,
            S1=,
            S2=,
            S3=,
            ONLINE=,
            IPConn=))

data_table = DataTable(source=source,width=1000, height=280)

def update_data():
    data,peername=Broadcast.send(6*1024)
    NAME,ID,S1,S2,S3,ONLINE=Broadcast.status(data,peername)
    data = dict(
            NAME=[NAME],
            ID=[ID],
            S1=[S1],
            S2=[S2],
            S3=[S3],
            ONLINE=[ONLINE],
            IPConn=[peername]
        )
    print data

    source.stream(data,3900)
curdoc().add_root(data_table)
curdoc().add_periodic_callback(update_data, 3900)

--
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/544cfb1a-e3bf-432b-9987-35ecc0e0a81b%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.