Sending updated x-range extents back to a server

I’m currently developing a Bokeh application which uses a Flask server. There is a line plot which the data source is an AjaxDataSource, and I would like to recompute it depending on the figure x range extents (zoom and reset tools are enabled on the figure). I have figured out how to set up the line AjaxDataSource by reviewing an existing reference (bokeh/ajax_source.py at branch-3.0 · bokeh/bokeh · GitHub) .

By following this example (not exactly the same, as it seems to be for an IPython Notebook), I am able to at least see (print) the current x_range start and end values - JavaScript callbacks — Bokeh 2.4.2 Documentation.

jscode = """
    var data = source.get('data')
    var start = cb_obj.get('start');
    var end = cb_obj.get('end');

    data['start'] = start;
    data['end'] = end;
    source.trigger('change');
//console.log('start =' + start)
//console.log('end =' + end)
"""

curr_fig.x_range.callback = CustomJS(
    args=dict(source=current_x_limits), code=jscode)

is there any way to connect the dots here - can I somehow use an Ajax post call in the CustomJS?  How would one go about doing this?

Is there a different way to tackle this problem?

I would like to be able to reference the possibly changed current_x_limits and do something to the main AjaxDataSource - recompute it depending on those limits.

@app.route(’/data’, methods=[‘GET’, ‘OPTIONS’, ‘POST’])
@crossdomain(origin="*", methods=[‘GET’, ‘POST’], headers=None)
def hello_world():

start = current_x_limits.data['start']
end = current_x_limits.data['end']

print('current_x_limits.start = ' + str(start))
print('current_x_limits.end = ' + str(end))
#recompute x and y data
return jsonify(x=data_source.data['x'],
               y=data_source.data['y'] )

I may have found something to help, which does something similar… - http://stackoverflow.com/questions/37083998/flask-bokeh-ajaxdatasource/37101669#37101669

···

On Wednesday, August 31, 2016 at 8:27:38 AM UTC-4, [email protected] wrote:

I’m currently developing a Bokeh application which uses a Flask server. There is a line plot which the data source is an AjaxDataSource, and I would like to recompute it depending on the figure x range extents (zoom and reset tools are enabled on the figure). I have figured out how to set up the line AjaxDataSource by reviewing an existing reference (https://github.com/bokeh/bokeh/blob/master/examples/howto/ajax_source.py) .

By following this example (not exactly the same, as it seems to be for an IPython Notebook), I am able to at least see (print) the current x_range start and end values - http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-range-update.

jscode = """
    var data = source.get('data')
    var start = cb_obj.get('start');
    var end = cb_obj.get('end');

    data['start'] = start;
    data['end'] = end;
    source.trigger('change');
//console.log('start =' + start)
//console.log('end =' + end)
"""

curr_fig.x_range.callback = CustomJS(
    args=dict(source=current_x_limits), code=jscode)

is there any way to connect the dots here - can I somehow use an Ajax post call in the CustomJS? How would one go about doing this?

Is there a different way to tackle this problem?

I would like to be able to reference the possibly changed current_x_limits and do something to the main AjaxDataSource - recompute it depending on those limits.

@app.route('/data', methods=['GET', 'OPTIONS', 'POST'])
@crossdomain(origin="*", methods=['GET', 'POST'], headers=None)
def hello_world():

    start = current_x_limits.data['start']
    end = current_x_limits.data['end']

    print('current_x_limits.start = ' + str(start))
    print('current_x_limits.end = ' + str(end))

    #recompute x and y data

    return jsonify(x=data_source.data['x'],
                   y=data_source.data['y'] )