Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

python - Serving interactive bokeh figure on heroku

I'm trying to serve an interactive bokeh figure via heroku. The figure I'm trying to have served is essentially equivalent to this one (example, code). I'm new to both bokeh and heroku so I'm pretty sure I'm missing something pretty basic -- I think what I'm trying to do should be quite straightforward.

First, I can serve my figure locally using the bokeh serve --show myapp command. Where myapp is the name of the python module that includes the bokeh figure. Note that the --show flag just prompts bokeh to open a browser window once the figure is built and the server is running.

Next, I've setup a heroku account, and created my first app, following the steps in the Heroku - Getting Started With Python tutorial. My git repository includes myapp, a requirements.txt file, and Procfile.

Alas, something is not working and I'm stumped. I have tried a bunch of different options in my Procfile and none have worked. Since the bokeh serve ... command starts a server, shouldn't a Procfile that looks like this do the trick:

web: bokeh serve --port $PORT myapp

Should that work? Perhaps I'm missing something and I need to create a flask app that wraps around my bokeh app but as far as I can tell, that doesn't seem necessary. Maybe someone knows of a nice tutorial that pulls all of these steps together, I haven't found a complete one yet.

Update: I'm pasting a bit of my heroku logs below. How do you handle this --host whitelist issue?

2016-07-17T05:00:46.513139+00:00 heroku[slug-compiler]: Slug compilation started
2016-07-17T05:00:46.366909+00:00 heroku[api]: Deploy 9b63d8a by [email protected]
2016-07-17T05:00:46.367087+00:00 heroku[api]: Release v4 created by [email protected]
2016-07-17T05:00:46.624937+00:00 heroku[web.1]: State changed from crashed to starting
2016-07-17T05:00:55.188978+00:00 heroku[web.1]: Starting process with command `bokeh serve --port=39665 myapp.py`
2016-07-17T05:00:57.876287+00:00 app[web.1]: 2016-07-17 05:00:57,876 Starting Bokeh server on port 39665 with applications at paths ['/myapp']
2016-07-17T05:00:57.868758+00:00 app[web.1]: 2016-07-17 05:00:57,868 Starting Bokeh server version 0.12.0
2016-07-17T05:00:57.876378+00:00 app[web.1]: 2016-07-17 05:00:57,876 Starting Bokeh server with process id: 3
2016-07-17T05:00:58.800309+00:00 heroku[web.1]: State changed from starting to up
2016-07-17T05:00:59.970326+00:00 app[web.1]: 2016-07-17 05:00:59,970 Rejected connection from host 'myapp.herokuapp.com' because it is not in the --host whitelist
2016-07-17T05:00:59.973495+00:00 app[web.1]: 2016-07-17 05:00:59,970 403 GET / (XX.XX.XXX.XX) 1.29ms
2016-07-17T05:00:59.975282+00:00 heroku[router]: at=info method=GET path="/" host=myapp.herokuapp.com request_id=xxxxxxxxxxxxx fwd="XX.XX.XX.XX" dyno=web.1 connect=1ms service=4ms status=403 bytes=219
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm just going to answer my own question since I was eventually able to get this to work and nobody else has answered it yet.

I ended up with a Procfile that looked like this:

web: bokeh serve --port=$PORT --host=myapp.herokuapp.com --host=* 
     --address=0.0.0.0 --use-xheaders myapp.py

a bit of background on what all of these arguments mean (as far as I can tell):

--port: specifies the port that the bokeh server will listen on, $PORT is set by heroku

--host=myapp.herokuapp.com and --host=*: specify the host name as myapp.heroku..., the wildcard is supposed to allow all hosts to be accepted. I'm not sure this in needed anymore.

--address=0.0.0.0: I think this tells bokeh to figure out on its own, which IP address it will be on.

--use-xheaders: causes bokeh to override the remote IP and URI scheme/protocol

I'm happy to make edits to this or accept a more knowledgeable users answer if there are issues with this approach.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...