I’ve created a bokeh server that serves a dashboard.
The dashboard has a template that looks like:
{% extends base %}
<!-- goes in head -->
{% block preamble %}
<style type="text/css">{% include 'styles.css' %}</style>
{% endblock %}
<!-- goes in body -->
{% block contents %}
<div id="main">
<div id="caption">
<div id="loaderContainer">
<div id="loaderTrigger">
{{ embed(roots.loaderTrigger) }}
</div>
<div id="loader"></div>
</div>
{{ embed(roots.caption) }}
</div>
<div id="contentArea">
<div id = "tableArea">
<div id = "selectFilters">
<div id = "selectFilter1">
{{ embed(roots.select_features1) }}
</div>
<div id = "selectFilter2">
{{ embed(roots.select_features2) }}
</div>
</div>
<div id = "dataTable">
{{ embed(roots.DataTable) }}
</div>
</div>
<div id="plotArea">
{{ embed(roots.plot) }}
</div>
</div>
</div>
{% endblock %}
Now, I’ve created a Flask app and I want to embed this dashboard by pulling a session from the bokeh server. I tried to follow this example but the dashboard there includes a single plot and has no template and styling.
How can I embed this dashboard so it will have the same html structure and styling as in the bokeh server?
from flask import Flask, render_template
from bokeh.client import pull_session
from bokeh.embed import server_session
def create_app() -> Flask:
app = Flask(__name__)
@app.route("/dashboards/<string:dashboard_name>", methods=["GET"])
def dashboards(dashboard_name):
dashboard_url = f"http://localhost:5100/{dashboard_name}"
with pull_session(url=dashboard_url) as session:
# generate a script to load the customized session
script = server_session(session_id=session.id, url=dashboard_url)
# use the script in the rendered page
return render_template("embed_dashboard.html", script=script, dashboard_name=dashboard_name)
return app
There are lots of combinations of possibilities, and I simply don’t know the answer about this specific combination, I am afraid. I can only say that the motivating usage scenario for Bokeh server templates was for the case that the Bokeh server was what was serving the entire page, not any embedding scenario.