Templates or workarounds when serving Panel through Flask

Two years ago the consensus seemed to be this is not possible

Since some time has passed, I thought it may be that things have changed in the meantime.

The problem seems to stem from the fact that the flask embedding strategy from https://github.com/bokeh/bokeh/blob/3.2.0/examples/server/api/flask_embed.py relies on letting the bokeh app generate the html, bypassing the templating.

@app.route('/', methods=['GET'])
def bkapp_page():
    script = server_document('http://localhost:5006/bkapp')
    return render_template("embed.html", script=script, template="Flask")

def bk_worker():
    server = Server({'/bkapp': bkapp}, io_loop=IOLoop(), allow_websocket_origin=["localhost:8000"])
  • Are the panel serve internals exposed in a way that would allow us to do something smarter here?
  • If not, would it be possible to inject parts of the app on multiple locations of the page? For example, one could create a sidebar in the static template embed.html and place some widgets there. I can see how maybe it would work with multiple bk_workers but you’d want them to share the internal state.