Black Lives Matter. Please consider donating to Black Girls Code today.

Auto-open browser window with Dash

Is there a simple way to cause the browser window on the correct port to automagically open (ala jupyter?). I’ve dug around a bit in the source of the jupyter project with no success so far. Bonus points if this can be done while using a more production-ready server (something like a gevent WSGI server example)…

Hi @dhhagan,

Would something using the webbrowser module work?

E.g.

import dash
...

import webbrowser
from threading import Timer

app = dash.Dash(__name__) 

port = 5000 # or simply open on the default `8050` port

def open_browser():
	webbrowser.open_new("http://localhost:{}".format(port))

if __name__ == '__main__':
    Timer(1, open_browser).start();
    app.run_server(debug=True, port=port)

(from https://stackoverflow.com/a/54235461)

1 Like