Multiple Ajaxdatasource call for a 3-glyph plot.

I already posted (a better readable post) on stackoverflow but had no answer: https://stackoverflow.com/questions/45301848/bokehflask-multiple-ajaxdatasource-calls

A simple 3-glyphs plot is giving me headache.
This is the 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 from db and 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()
        )

Why is AjaxDataSource called 3 times, once for each glyph (they are a few milliseconds apart, then the triple reading is done again after 5 seconds) instead of only once every 5 seconds, one reading for the 3 glyphs?

I believed that AjaxDataSource fills dynamically data_source.data every 5 seconds and then, after they have been read, the 3 lines read these “now static” data.

It has been answered on Stackoverflow by Eugene Pachomov and it is a Bokeh issue.

His workaround works perfectly.

“”"
The issue is that each glyph that has a remote data source attached to it, tries to initialize the data source. In the case of AjaxDataSource, it doesn’t check for previous initializations.

I’ve opened an issue for it: https://github.com/bokeh/bokeh/issues/6736

A temporary workaround that you could 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 that this code is run right after Bokeh is included in your
page, but before it initializes its documents. How to do it depends on how you embed Bokeh.

“”"