Failed to load resources (404) nginx + gunicorn + flask + bokeh

Hi,

I have this piece of Flask code loading a bokeh server

@app.route('/candlechart')
def candleChart():
    refAsset = request.args.get('ref')
    tradeAsset = request.args.get('trade')
    
    # Retrieve the script to include the bokeh app to the page.
    script = server_document("/bokeh_server/candle_chart", relative_urls=True, arguments={"ref":refAsset, "trade":tradeAsset})
    return render_template("candleChart.html", script=script, template="Flask")

My nginx config transforms
localhost/bokeh_server/candle_chart
to
localhost:5006/candle_chart
And is also configured to access the flask server using the /flask url. For example, to access the candlechart page of the Flask server I use : localhost/flask/candlechart

So the URL used to start the bokeh server app is :
localhost/flask/candlechart?ref=EUR&trade=BTC

In bokeh 1.3.4 this is working fine.
In browser console I have :

Bokeh: injecting script tag for BokehJS library:  https://cdn.pydata.org/bokeh/release/bokeh-1.3.4.min.js autoload.js:79:15
...
Bokeh: all BokehJS libraries/stylesheets loaded

which is fine.

When try with 1.4.0, bokeh doesn’t load.
In browser console I have

Bokeh: injecting script tag for BokehJS library:  static/js/bokeh.min.js?v=ac90935137e13ae0b2c6583f2e1f3fe8
...
Le script à l’adresse « http://localhost/flask/static/js/bokeh.min.js?v=ac90935137e13ae0b2c6583f2e1f3fe8 » a été chargé alors que son type MIME (« text/html ») n’est pas un type MIME JavaScript valide.
candlechart
failed to load static/js/bokeh-gl.min.js?v=817fa55a6e55d1e469275e21c9b77565 autoload.js:57:15
    on_error http://localhost/bokeh_server/candle_chart/autoload.js?bokeh-autoload-element=1001&bokeh-app-path=/bokeh_server/candle_chart&ref=EUR&trade=BTC:57

It only says “failed to load” only for bokeh-gl.min.js but the MIME type warning is there for all of the .js

Is there a way to :

  • load the resources through the CDN like in 1.3.4
    or
  • make the local resources loading work (I guess this one would be preferable)

Thanks !

The bug that prevented using CDN resources with 1.4 was fixed in master, but will not show up in a release until 2.0 (tentatively looking at January).

Otherwise, local usage should just work. Are you missing that file in your Bokeh installation? E.g. you should see ir in a location like this:

(dev) ❯ ls  -al ~/anaconda/envs/140/lib/python3.7/site-packages/bokeh/server/static/js/ |grep gl
 -rw-rw-r--  2 bryan staff 109K Nov  4 10:14 bokeh-gl-es6.js
 -rw-rw-r--  2 bryan staff  62K Nov  4 10:14 bokeh-gl-es6.min.js
 -rw-rw-r--  2 bryan staff 111K Nov  4 10:14 bokeh-gl.js
 -rw-rw-r--  2 bryan staff  63K Nov  4 10:14 bokeh-gl.min.js

If it is not there, then your package install is broken for some reason. If it is there, then we really need a minimal reproducer to try and run to test with ourselves.

1 Like

Thanks !

I can stick to 1.3.4 meanwhile.
The local bokeh files are there, I will try to fix this. Maybe it is because of Flask, which serves a specific folder for static files. I’ll try to add this folder to the static files served by Flask.

1 Like

I ended up copying all the bokeh*.js files to the default Flask static folder. It’s now working on 1.4.0 !

1 Like