Bokeh models load after reload of Flask server

I am starting a Bokeh model with a Flask server. Hereby, I use the pull_session function and the plot gets displayed without a problem. I need to use an autoload script because the plot is rather complex with its interactivity.

@app.route("/plot")
def plot_page():
    global app_url

    with pull_session(url=app_url) as session:

        script = server_session(session_id=session.id, url=app_url)

        return render_template("embed.html", script=script, template="Flask")

I now want to change the plot by editing the server.document.

@app.route("/plot")
def plot_page():
    global app_url

    with pull_session(url=app_url) as session:

        session.document.roots[0].children[5].children[0].children[0].children[0].value = "Magma"
        script = server_session(session_id=session.id, url=app_url)

        return render_template("embed.html", script=script, template="Flask")

The inserted code should update a colormap parameter in the plot. After I reload the page the plot does not get displayed. Debug console output:

Bokeh: BokehJS not loaded, scheduling load and callback at Sat Jun 06 2020 12:14:13 GMT+0200 (Central European Summer Time)
autoload.js?bokeh-autoload-element=1450&bokeh-app-path=/main_backend&bokeh-absolute-url=http://localhost:5010/main_backend&bokeh-session-id=DkKpIuPB4MuWhwsUkq8xrtEMp5j8vAESaWSxZRDXNmGM:57 Bokeh: injecting script tag for BokehJS library:  http://localhost:5010/static/js/bokeh.min.js?v=afab3eba5b3a72c05610143940e03c8e
autoload.js?bokeh-autoload-element=1450&bokeh-app-path=/main_backend&bokeh-absolute-url=http://localhost:5010/main_backend&bokeh-session-id=DkKpIuPB4MuWhwsUkq8xrtEMp5j8vAESaWSxZRDXNmGM:57 Bokeh: injecting script tag for BokehJS library:  http://localhost:5010/static/js/bokeh-widgets.min.js?v=68fceb4be2f3d6410ff2d7704c8b87cf
autoload.js?bokeh-autoload-element=1450&bokeh-app-path=/main_backend&bokeh-absolute-url=http://localhost:5010/main_backend&bokeh-session-id=DkKpIuPB4MuWhwsUkq8xrtEMp5j8vAESaWSxZRDXNmGM:57 Bokeh: injecting script tag for BokehJS library:  http://localhost:5010/static/js/bokeh-tables.min.js?v=02bdadb2c698bc2855a4d4a69c163821
autoload.js?bokeh-autoload-element=1450&bokeh-app-path=/main_backend&bokeh-absolute-url=http://localhost:5010/main_backend&bokeh-session-id=DkKpIuPB4MuWhwsUkq8xrtEMp5j8vAESaWSxZRDXNmGM:57 Bokeh: injecting script tag for BokehJS library:  http://localhost:5010/static/js/bokeh-gl.min.js?v=70e18d8dcea09947c12764bf85ec76a0
autoload.js?bokeh-autoload-element=1450&bokeh-app-path=/main_backend&bokeh-absolute-url=http://localhost:5010/main_backend&bokeh-session-id=DkKpIuPB4MuWhwsUkq8xrtEMp5j8vAESaWSxZRDXNmGM:50 Bokeh: all BokehJS libraries loaded
autoload.js?bokeh-autoload-element=1450&bokeh-app-path=/main_backend&bokeh-absolute-url=http://localhost:5010/main_backend&bokeh-session-id=DkKpIuPB4MuWhwsUkq8xrtEMp5j8vAESaWSxZRDXNmGM:135 Bokeh: BokehJS plotting callback run at Sat Jun 06 2020 12:14:13 GMT+0200 (Central European Summer Time)
logging.js:130 [bokeh] setting log level to: 'info'
autoload.js?bokeh-autoload-element=1450&bokeh-app-path=/main_backend&bokeh-absolute-url=http://localhost:5010/main_backend&bokeh-session-id=DkKpIuPB4MuWhwsUkq8xrtEMp5j8vAESaWSxZRDXNmGM:113 Bokeh: injecting CSS: http://localhost:5010/static/css/bokeh.min.css?v=4c253f78f16b7d5d0c9d1df8062c7f4c
autoload.js?bokeh-autoload-element=1450&bokeh-app-path=/main_backend&bokeh-absolute-url=http://localhost:5010/main_backend&bokeh-session-id=DkKpIuPB4MuWhwsUkq8xrtEMp5j8vAESaWSxZRDXNmGM:115 Bokeh: injecting CSS: http://localhost:5010/static/css/bokeh-widgets.min.css?v=6f280acb818327130a8c244ce05fd10d
autoload.js?bokeh-autoload-element=1450&bokeh-app-path=/main_backend&bokeh-absolute-url=http://localhost:5010/main_backend&bokeh-session-id=DkKpIuPB4MuWhwsUkq8xrtEMp5j8vAESaWSxZRDXNmGM:117 Bokeh: injecting CSS: http://localhost:5010/static/css/bokeh-tables.min.css?v=86c18b0b1fd30cdbc124e60cb9452e73
autoload.js?bokeh-autoload-element=1450&bokeh-app-path=/main_backend&bokeh-absolute-url=http://localhost:5010/main_backend&bokeh-session-id=DkKpIuPB4MuWhwsUkq8xrtEMp5j8vAESaWSxZRDXNmGM:27 Bokeh: all callbacks have finished
connection.js:183 [bokeh] Websocket connection 0 is now open

When I restart the Flask server (debug mode is active so I just save the server file), the bokeh items get rendered and the plot gets displayed. New output on debug console:

13widget_box.js:98 [bokeh] WidgetBox mode is fixed, but no width specified. Using default of 300.
document.js:87 [bokeh] document idle at 539 ms
index.js:64 Bokeh items were rendered successfully

Have I overlooked something or is there a better way to change the bokeh document?