
Hello!
I am trying to stream data to a DataTable and it seems I am missing some basic piece of knowledge. Every second I stream a new datapoint to the table. The point contains current timestamp and some random number. My problem is that the new datapoint gets appended to the end of the table. Unless the users clicks the header and sorts the table all the new points will be appended to the end. Is it possible somehow to stream data to the top of the table? Or to programmatically enforce the sorting of the table?
The end result should be that without user interaction the table should just show newest datapoint at the top of the table.
I know I could sort the whole dataset myself and then do source.data = data. But this will be far less efficient than simple stream of one point.
Here is an example code that currently streams to the bottom of the table. Is there something I can do to force the new point to be at top of the table?
import bokeh.models
import bokeh.plotting
import pandas as pd
import numpy as np
doc = bokeh.plotting.curdoc()
source = bokeh.models.ColumnDataSource(data=dict(
timestamp=[pd.Timestamp.now()],
number=[np.random.normal()],
))
columns = [
bokeh.models.TableColumn(
field="timestamp",
title="Timestamp",
formatter=bokeh.models.DateFormatter(format="%H:%M:%S")),
bokeh.models.TableColumn(
field="number",
title="Number",
formatter=bokeh.models.NumberFormatter(format=".00")),
]
table = bokeh.models.DataTable(
source=source,
columns=columns
)
def stream_point():
source.stream(dict(timestamp=[pd.Timestamp.now()], number=[np.random.normal()]))
doc.add_periodic_callback(stream_point, 1000)
doc.add_root(table)
Thanks for help in advance!


