python - Bokeh+Flask: Multiple AjaxDataSource calls -


a bokeh object figure shows 3 indipendent lines.

data streamed. ajaxdatasource call updates data every 5 seconds reading last ones database.

this stripped down class:

class graph:     def __init__(self):          data_source = ajaxdatasource(data=dict(date_time=[],                                                value_1=[],                                                 value_2=[],                                                 value_3=[]),                                                 data_url="/data",                                                polling_interval=5000)          line1 = self.figure.line(x="date_time", y="value_1", source=data_source)         line2 = self.figure.line(x="date_time", y="value_2", source=data_source)         line3 = self.figure.line(x="date_time", y="value_3", source=data_source)          app.add_url_rule("/data", "/data", self.serve, methods=['get', 'options', 'post'])      def serve(self):          # load data db , return json         ...         return jsonify(             date_time= da.df["date_time"].tolist(),             value_1=da.df["value1"].tolist(),             value_2=da.df["value2"].tolist(),             value_3=da.df["value3"].tolist()         ) 

date_time common x-axis, value_1 line 1, value_2 line 2, value_3 line 3.

the problem

why ajaxdatasource called 3 times (they few milliseconds apart, triple reading done again after 5 seconds) instead of once every 5 seconds?

i believed ajaxdatasource fills dynamically data_source.data every 5 seconds , then, after have been read, 3 lines read these "now static" data.

workaround?

is there way read data using ajaxdatasource, transfer automatically data columndatasource , use "static" data source?

or missing important here?

the issue each glyph has remote data source attached it, tries initialize data source. in case of ajaxdatasource, doesn't check previous initializations.

i've opened issue it: https://github.com/bokeh/bokeh/issues/6736

a temporary workaround try:

bokeh.require('models/sources/ajax_data_source').ajaxdatasource.prototype.setup = function () {     this.get_data(this.mode);     if (this.polling_interval && this.interval == null) {         return this.interval = setinterval(this.get_data, this.polling_interval, this.mode, this.max_size, this.if_modified);     } } 

make sure code run right after bokeh included in page, before initializes documents. how depends on how embed bokeh.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -