Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Webbrowser.open(...) in DASH app in debug mode causes two identical web pages to load

Hello, I’m new to DASH and just learning the ropes. I’m developing a DASH app with Pycharm

I wanted to set it up so that the app automatically opens the browser and loads the page when the program is run, as opposed to having to click on the link that is placed in the console window.

I followed the recommendation to do it like this:

def open_browser(port=5000):
webbrowser.open_new(f"http://localhost:{port}")

… set up app
Timer(1, open_browser).start()
app.run_server(port=5000, debug=True)

What happens then is that it invokes the main program a second time, with a separate process ID immediately after it has loaded the web page once, so I get two tabs in the web browser, both running the program independently.

This is irrespective of browser used ( tried Chrome and Edge).

The issue only occurs if I have app.run_server with debug set to True. If debug is set to False then only one process is created.

If I don’t use the Timer/open_browser combination, when I click on the link http://127.0.0.1:5000/ then it only opens one tab on the browser, even if debug is set to True.

Can anyone explain this?

Update - this does not appear to be a Pycharm issue - the same behaviour happens if I run it from a command prompt.