On Aug 20, 2018, at 08:42, [email protected] wrote:
RE custom templating for bokeh embedded in Flask: am I right in thinking that the ability to extend the standard Jinja template only applies when you want to save a static html file?
In a related issue, when I try to extract a single model from a session pulled from a bokeh server (to send to a template in a Flask app) using `server_session(model=...)`, the resulting script renders *all* models from the document rather than just the one I specified.
Issue aside, would multiple calls to server_session(model=...) be a sensible way to get custom placement for multiple models in a Flask app?
For reproducing (I'm using Bokeh 0.13.0 and Flask 1.0.2):
bokeh_app.py
from bokeh.io import curdoc
from bokeh.plotting import figure
p0 = figure(x_range=(0,10), y_range=(0,10))
p1 = figure(sizing_mode="scale_width", x_range=(0,10), y_range=(0,10))
curdoc().add_root(p0)
curdoc().add_root(p1)
serve.py
from flask import Flask, render_template
from bokeh.client import pull_session
from bokeh.embed import server_session
app_url = "http://localhost:5100/bokeh_app"
app = Flask(__name__)
@app.route('/')
def bkapp_page():
with pull_session(url=app_url) as session:
model = session.document.roots[0]
script = server_session(model=model, session_id=session.id, url=app_url)
return render_template("embed.html", script=script)
embed.html
<!DOCTYPE html>
<html lang="en">
<body>
{{ script | safe }}
</body>
</html>
bokeh serve --port 5100 --allow-websocket-origin localhost:8080 --allow-websocket-origin 127.0.0.1:8080bokeh_app.py
Thanks for any advice, and thanks again for providing such an incredible library—I fully abandoned Matlab after discovering bokeh.
Stephen
In my previous messages, I think I was confusing the custom templating method for *saving* html documents, with custom templating within a Flask app that pulls a session from bokeh server (thinking that I could extend the bokeh Jinja template in Flask). My under
if I want a Flask app to be able to control placement of multiple models from a document served by `bokeh serve`,
On Friday, August 17, 2018 at 5:21:33 PM UTC+1, Stephen Gaffney wrote:
Hi again,
My last message wasn't so much an answer as a way of hiding the error. Could anyone help me work out what the intended 'embed.html' file should look like in examples/embed/server_session? The user guide gives some code here, providing template shown below, but I think it needs modification to work.
{% extends base %}
<!-- goes in head -->
{% block preamble %}
<link href="app/static/css/custom.min.css" rel="stylesheet">
{% endblock %}
<!-- goes in body -->
{% block contents %}
<div> {{ embed(roots.scatter) }} </div>
<div> {{ embed(roots.line) }} </div>
{% endblock %}
The render_template call is:
return render_template("embed.html", script=script, template="Flask"
)
Thanks,
Stephen
--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e6ab35d2-ae25-45a2-9bb8-4153bd01f7bd%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.