Forums

Bokeh embed with flask -

Good morning,

I have developed a bokeh app embed with flask. I put it online, it works perfectly when I try to connect to the website with my computer with Chrome and Safari. However, when anyone else or another computer is trying to connect to the website he gets this message :

Failed to load resource: net::ERR_CONNECTION_REFUSED

http://localhost:5006/bkapp/autoload.js?bokeh-autoload-element=1004&bokeh-app-path=/bkapp&bokeh-absolute-url=http://localhost:5006/bkapp

Which correspond to display of the bokeh plots extracted from the bokeh server. Here is the configuration of the bokeh and flask server :

def bkapp(doc):
   doc.add_root(Interface().doc)


@app.route('/', methods=['GET'])
def bkapp_page():
    script = server_document('http://localhost:5006/bkapp')
    return render_template("embed.html", script=script, template="Flask")


def bk_worker():
    server = Server({'/bkapp': modify_doc}, io_loop=IOLoop(),host="localhost:5006",allow_websocket_origin=['*'])
    server.start()
    server.io_loop.start()

from threading import Thread
Thread(target=bk_worker).start()

if __name__ == '__main__':                                                    
    app.run(port=8000)

I am totally lost, I tried different configuration but impossible to get one working with another user.

Thank you a lot for you help,

Best regards,

Looks like you run it on your local machine, not on PythonAnywhere. On PythonAnwhere you don't run anything on some arbitrary port of localhost. You need to deploy your web app using "Web" configuration page and wsgi file. Here is an example for Flask: https://help.pythonanywhere.com/pages/Flask/

You part true, I found why it was working on my computer : I was also running it on my local machine in the same time. Therefore, it was binding my local server to the webpage.

But I configured the WSFI file properly. The error I displayed was the error occurring when I try to reach my web app with the url.

I also find another post in the forum saying that web socket connections are not allowed with pythonanywhere. Basically it is not possible to listen to the bokeh server in order to display into the flask HTML file. I am currently looking for another web host since it is not possible with pythonanywhere...