Drew
May 21, 2020, 6:41pm
1
When I run my bokeh app locally, following the flask_embed.py example on the Bokeh Git, it works fine. But running it on Heroku, it shows the html template page but not the Bokeh app.
I can attach the heroku error logs if need be. Thanks.
def bkapp(doc):
textin = TextInput(title = "Submit Blog Post:")
button = Button(label="Submit", button_type="success")
p = Paragraph(text="Blog entry here")
def update_data(event):
data = str(textin.value)
vector = transformer.transform([' '.join(clean(data))])
result = model.predict(vector)
if int(result) == 1:
pred_text = 'Male'
else:
pred_text = 'Female'
output = {'prediction': pred_text}
p.text = "{}".format(output)
button.on_click(update_data)
box = WidgetBox(children = [textin, button, p])
doc.add_root(box)
@app.route('/', methods=['GET'])
def bkapp_page():
script = server_document('https://blog-nlp.herokuapp.com/bkapp')
return render_template("embed.html", script=script, template="Flask")
def bk_worker():
server = Server({'/bkapp': bkapp}, io_loop=IOLoop())
server.start()
server.io_loop.start()
Thread(target=bk_worker).start()
if __name__ == '__main__':
app.run()
Bryan
May 21, 2020, 7:19pm
2
This is always advised. Browser JS console logs as well.
Drew
May 21, 2020, 7:39pm
3
Thanks Bryan
2020-05-21T19:35:41.822243+00:00 app[web.1]: Exception in thread Thread-1:
2020-05-21T19:35:41.822268+00:00 app[web.1]: Traceback (most recent call last):
2020-05-21T19:35:41.822269+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/threading.py", line 926, in _bootstrap_inner
2020-05-21T19:35:41.822270+00:00 app[web.1]: self.run()
2020-05-21T19:35:41.822271+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/threading.py", line 870, in run
2020-05-21T19:35:41.822271+00:00 app[web.1]: self._target(*self._args, **self._kwargs)
2020-05-21T19:35:41.822271+00:00 app[web.1]: File "/app/bkflask.py", line 52, in bk_worker
2020-05-21T19:35:41.822272+00:00 app[web.1]: server = Server({'/bkapp': bkapp}, io_loop=IOLoop())
2020-05-21T19:35:41.822272+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/bokeh/server/server.py", line 390, in __init__
2020-05-21T19:35:41.822273+00:00 app[web.1]: sockets, self._port = bind_sockets(self.address, self.port)
2020-05-21T19:35:41.822273+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/bokeh/server/util.py", line 60, in bind_sockets
2020-05-21T19:35:41.822274+00:00 app[web.1]: ss = netutil.bind_sockets(port=port or 0, address=address)
2020-05-21T19:35:41.822274+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/tornado/netutil.py", line 174, in bind_sockets
2020-05-21T19:35:41.822274+00:00 app[web.1]: sock.bind(sockaddr)
2020-05-21T19:35:41.822275+00:00 app[web.1]: OSError: [Errno 98] Address already in use
2020-05-21T19:35:41.822275+00:00 app[web.1]:
2020-05-21T19:36:33.641749+00:00 heroku[router]: at=info method=GET path="/bkapp/autoload.js?bokeh-autoload-element=1001&bokeh-app-path=/bkapp&bokeh-absolute-url=https://blog-nlp.herokuapp.com/bkapp" host=blog-nlp.herokuapp.com request_id=2b39ef47-a487-4957-9a7b-3a89e973607c fwd="68.129.186.174" dyno=web.1 connect=1ms service=7ms status=404 bytes=400 protocol=https
2020-05-21T19:36:33.641130+00:00 app[web.1]: 10.61.164.89 - - [21/May/2020:19:36:33 +0000] "GET /bkapp/autoload.js?bokeh-autoload-element=1001&bokeh-app-path=/bkapp&bokeh-absolute-url=https://blog-nlp.herokuapp.com/bkapp HTTP/1.1" 404 232 "http://127.0.0.1:5000/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0"
^C
Bryan
May 21, 2020, 7:43pm
4
Well, this is certainly a problem:
Usually that occurs if you start a server process once, then try to start a second server process on the same port. I am afraid I don’t have any specific experience with Heroku to be able to say much more than that, though.
I don’t have much experience with embedding Bokeh like that, but I don’t think you can do it this particular way on Heroku. You’re using a public URL with server_document
, and the Bokeh server cannot listen on the port associated with that URL on Heroku when your own Flask server listens on that port. Try replacing https://blog-nlp.herokuapp.com
with http://localhost:5006
. You may also need to explicitly pass address='localhost'
to Server
(port 5006 is the default one).
Drew
May 22, 2020, 1:22pm
6
Sure, these commands work when deploying the app locally. But when I want to deploy it on Heroku it gives an AppError for that /bkapp page.