Deploying Bokeh+Flask Model to Heroku, Bokeh Doesn't Appear

When I run my bokeh app locally, following the 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'
            pred_text = 'Female'
        output = {'prediction': pred_text}
        p.text = "{}".format(output)
    box = WidgetBox(children = [textin, button, p])
@app.route('/', methods=['GET'])
def bkapp_page():
    script = server_document('')
    return render_template("embed.html", script=script, template="Flask")

def bk_worker():
    server = Server({'/bkapp': bkapp}, io_loop=IOLoop())


if __name__ == '__main__':

This is always advised. Browser JS console logs as well.

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/", line 926, in _bootstrap_inner
2020-05-21T19:35:41.822270+00:00 app[web.1]:
2020-05-21T19:35:41.822271+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/", 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/", 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/", 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/", 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/", 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=" request_id=2b39ef47-a487-4957-9a7b-3a89e973607c fwd="" dyno=web.1 connect=1ms service=7ms status=404 bytes=400 protocol=https
2020-05-21T19:36:33.641130+00:00 app[web.1]: - - [21/May/2020:19:36:33 +0000] "GET /bkapp/autoload.js?bokeh-autoload-element=1001&bokeh-app-path=/bkapp&bokeh-absolute-url= HTTP/1.1" 404 232 "" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0"

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 with http://localhost:5006. You may also need to explicitly pass address='localhost' to Server (port 5006 is the default one).

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.