在 heroku 上提供交互式散景图 [英] Serving interactive bokeh figure on heroku
问题描述
我正在尝试通过 heroku 提供交互式 bokeh
图形.我试图提供的数字基本上等同于这个(example, bokeh
和 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.
首先,我可以使用 bokeh serve --show myapp
命令在本地提供我的人物.其中 myapp
是包含 bokeh
图形的 python 模块的名称.请注意,--show
标志只会提示 bokeh
在图形构建完毕且服务器运行后打开浏览器窗口.
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.
接下来,我已经设置了一个 heroku
帐户,并按照 Heroku - Python 入门 教程.我的 git 存储库包括 myapp
、requirements.txt
文件和 Procfile
.
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
.
唉,有些东西不起作用,我很难过.我在我的 Procfile
中尝试了许多不同的选项,但都没有奏效.由于 bokeh serve ...
命令启动了一个服务器,看起来像这样的 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
那应该行吗?也许我遗漏了一些东西,我需要创建一个 flask
应用程序来环绕我的 bokeh
应用程序,但据我所知,这似乎没有必要.也许有人知道一个很好的教程,可以将所有这些步骤整合在一起,但我还没有找到完整的教程.
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.
更新:我正在下面粘贴一些我的 heroku
日志.你如何处理这个 --host whitelist
问题?
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 me@me.com
2016-07-17T05:00:46.367087+00:00 heroku[api]: Release v4 created by me@me.com
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
推荐答案
我只是要回答我自己的问题,因为我最终能够让它发挥作用,而其他人还没有回答.
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.
我最终得到了一个看起来像这样的 Procfile
:
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
:指定bokeh
服务器监听的端口,$PORT
由heroku设置代码>
--port
: specifies the port that the bokeh
server will listen on, $PORT
is set by heroku
--host=myapp.herokuapp.com
和 --host=*
:指定主机名为 myapp.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
:我认为这会告诉 bokeh
自己确定它将位于哪个 IP 地址.
--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
:导致 bokeh
覆盖远程 IP 和 URI 方案/协议
--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.
这篇关于在 heroku 上提供交互式散景图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!