I'm trying to use Bokeh's 'create_html_snippet' method to present pandas/seaborn plots in a webpage.
As a test I cloned @rpazyaquian's demo repo here - https://github.com/rpazyaquian/bokeh-flask-tutorial/wiki/Rendering-Bokeh-plots-in-Flask. Unfortunately, it doesn't work due to a change in bokeh since the repo was created.
The main HTML output on the page is exactly the same, except obviously the unique bokeh file name is different.
The only difference overall is in the bokeh-generated *.embed.js file. As shown in the excerpts below, the host / static path variables in that file don't seem to work properly. Tested with both the built-in Flask dev server and with gunicorn.
Here's the top part of the working version on @rpazyaquian's Heroku site:
var host = "";
var staticRootUrl = "http://localhost:5006/bokeh/static/";
if (host!=""){
staticRootUrl = host + "/static/";
var bokehJSUrl = window.location.protocol + "//" + staticRootUrl + "js/bokeh.js";
}
else {
bokehJSUrl = staticRootUrl +"js/bokeh.js";
}
Here's the not-working local version, using Heroku 0.4:
var host = "";
var staticRootUrl = "http://localhost:5006/bokeh/static/";
if (host!=""){
staticRootUrl = "//" + host + "/bokehjs/static/";
var bokehJSUrl = staticRootUrl + "js/bokeh.js";
}
else {
bokehJSUrl = staticRootUrl +"js/bokeh.js";
}
Obvious issues:
http://localhost:5006
, it's http://127.0.0.1:5000/
when using the dev server or whatever you choose if using gunicorn / nginxAny ideas on what has changed in Bokeh that could fix this? Or alternatively anyone who's successfully serving Bokeh plots through Flask templates using an alternative method - let me know if there's a better route. I'm just trying to return the HTML snippet for a chart to output into a template.
UPDATE: this function has been deprecated. Please now use the much better bokeh.embed
module:
https://github.com/ContinuumIO/bokeh/blob/master/bokeh/embed.py
You can see some examples of its use at:
https://github.com/ContinuumIO/bokeh/tree/master/examples/embed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With