
I am creating a dashboard for displaying live data which i am collecting from multiple sensors.
The data is collected in a dictionary via an update function running in a separate thread, which is started by on_server_loaded() in app_hooks.py, similar to the spectrogram example app.
I am using this dictionary as a ColumnDataSource for displaying the data in the Bokeh app.
I am currently updating the data in the Bokeh graphs via source.data, but this sends all the data again which i would like to avoid.
source.stream() allows me to only send new_data to the web page but it also updates the source (ColumnDataSource) which is the dictionary in which the new data from the sensors is collected by the separate thread.
This causes doubling of every point in the dictionary, every point is first added by the separate thread and then again by the stream method.
Is there a way to prevent the stream method from adding the new_data to the source dictionary.
I know I could crate a new empty dictionary and use it as a ColumnDataSource, but this would double up the points server side, more if multiple pages are open.
As i am hoping to run this on a raspberry pi 3B+ (1GB RAM) i would like to minimize server side memory usage.
Is there anyway to only send new data to the web page without updating the server side ColumnDataSource?
What i am currently using:
from .bkh_lib.data_holder import dev_data_global # dictionary with the sensor data
source = ColumnDataSource(data=dev_data_global['plot_data'])
def update_bkh():
# function used to periodically update bkh web page data if there are new points
if len(dev_data_global['plot_data']['x']) != data_length:
source.data = dev_data_global['plot_data']
data_length = len(dev_data_global['plot_data']['x'])
doc.add_periodic_callback(update_bkh, update_time)
Stream version:
from .bkh_lib.data_holder import dev_data_global # dictionary with the sensor data
source = ColumnDataSource(data=dev_data_global['plot_data'])
def update_bkh():
# function used to periodically update bkh web page data if there are new points
if len(dev_data_global['plot_data']['x']) != data_length:
new_data = {
'x' = dev_data_global['plot_data']['x'][data_length:]
'y' = dev_data_global['plot_data']['y'][data_length:]
}
source.stream(new_data)
data_length = len(dev_data_global['plot_data']['x'])
doc.add_periodic_callback(update_bkh, update_time)

