Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the static path variables set in Bokeh (for create_html_snippet)

Tags:

python

bokeh

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:

  1. The host isn't http://localhost:5006, it's http://127.0.0.1:5000/ when using the dev server or whatever you choose if using gunicorn / nginx
  2. I don't know where the 'bokehjs' folder is being set - but it doesn't seem relevant here.

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

like image 984
Phil Sheard Avatar asked Oct 02 '22 05:10

Phil Sheard


1 Answers

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

like image 90
bigreddot Avatar answered Oct 05 '22 22:10

bigreddot