TemplateNotFound error in examples/embed/server_session

Hi,

The server_session example (examples/embed/server_session) is failing for me with the exception: “jinja2.exceptions.TemplateNotFound: embed.html”.

Should there be a ‘templates/’ folder in that example directory containing ‘embed.html’?

I’m using Bokeh 0.13.0 (and have got the same error with 0.12.16 and the latest dev release); and Flask 1.0.2 (and have also tried 0.12).

I see the arguments ‘embed.html’ and template=“Flask” are also used in the user guide here: Embedding Bokeh content — Bokeh 2.4.2 Documentation

Any advice on how to get a flask app to find bokeh templates would be a great help.

Thanks,

Stephen

Oh, just stumbled on the answer. There is indeed a templates folder missing from that example, but this one also works: examples/howto/server_embed/templates

Best,

Stephen

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

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

{{ script | safe }}

``

bokeh serve --port 5100 --allow-websocket-origin localhost:8080 --allow-websocket-origin 127.0.0.1:8080 bokeh_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

Hi,

There is an example of templating individual components in a template used directly by the Bokeh server here:

  https://github.com/bokeh/bokeh/tree/master/examples/app/dash

I guess my recommendation would be so see if there is a way to make that scenario work, instead. AFAIK embedding individual components in a separate web app (e.g. Flask) template is uncharted territory. It may work, but offhand I am not sure how to put it together.

Thanks,

Bryan

···

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&quot;

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\.

Thank you! That’s a very useful example, and looks like a sensible approach for what I need.

Stephen