How to modify figure via ajax in flask + bokeh server

Hello everyone,

I am currently working on a flask app + bokeh server. I have a file where a bokeh’s figure is created and a separate flask file - I am wondering if I can modify the figure via custom ajax call, for example to change the color of the plot by clicking on a button. I don not how to access source which is in from Ideally, I would prefer to merge and but I do not know how to deal with bokeh server. Here is my sample code: (bokeh serve --allow-websocket-origin=

from import curdoc
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure

x = [1, 2, 3]

source = ColumnDataSource(data=dict(x=[1, 2, 3],
y=[1, 2, 3],
color=[‘red’] * len(x)))

fig = figure(plot_width=900, plot_height=300)“x”, “y”, color=“color”, source=source,)



from flask import render_template, Flask, request, jsonify, url_for
from bokeh.embed import autoload_server
from bokeh.client import pull_session

app = Flask(name)

def index():
session = pull_session(app_path=’/bokeh_plot’)
script = autoload_server(None, app_path="/bokeh_plot",
return render_template(“home.html”, script=script)

@app.route(’/color’, methods=[“POST”, “GET”])
def change_color():
color = request.json[‘color’]
# Need to access source in bokeh_plot to change the color
return jsonify(ok=“ok”)

if name == ‘main’:




$("#green").on('click', function(){
    type: "POST",
    url: "/color",
        contentType: 'application/json; charset=UTF-8',
         data: JSON.stringify({'color': "green"}),
         dataType: 'json',
    success: function(data){
    error: function(){




<!doctype html>

Flask Bokeh

Welcome to Flask and Bokeh

{{script | safe }}



<script src="//"></script>
Enter code here...


Any suggestions on how to solve this problem are highly appreciated.

Thanks for your time,