Dash is opening 2 windows when running code

For some reason when I run my Dash app in VSCode in my .py file it is opening two tabs. One tab has my entire Dash app as it should normally appear. After making some selections and clicking a button to generate a graph, it generates the graph (expected) but then it opens a second tab with only the graph displayed, no other dash components. Now here’s the weird behavior.

I also have the same exact code in a .ipynb and upon startup of my machine, the .ipynb opens one tab as behaves completely normal. Once I open the .py file then it behaves oddly by opening the second tab with only the graph. If I go back to the .ipynb file it now opens two tabs rather than one as before. I then tried restarting the computer again and opened the .py file first and it still opens two tabs. The first tab opens in “http://127.0.0.1:8050/” as expected but the second window opens in “http://127.0.0.1:50969/” which is odd.

I did some digging and found that everyone had suggested using:

if __name__ == '__main__':
    app.run_server(debug=True, use_reloader=False)

but I already had that in my code previously and it is still opening two tabs. I also tried setting debug=False and erasing the use_reloader statement and still no luck. Can anyone help or does someone know why this behavior is happening? I have never experienced this before with any other Dash app I have made.

If you guys like I can paste my app but I figure it may be unnecessary and it is around 335 lines of code.

hi @Rettro
:wave: welcome to the community.

I’ve actually never experienced that before. Do you get the same behavior if you just do?

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

app.run() Does not work for me. I get an error “AttributeError: ‘Dash’ object has no attribute ‘run’”. Currently I am running Dash 2.0.0.

can you upgrade to Dash==2.6.2?

Hello @Rettro,

I think you probably have a fig.show() in your code, this will automatically open a new browser window.

Instead, you should be returning the figure to your layout.

2 Likes

Thank you! I also had asked my boss and he also saw that this was the problem. Removing fig.show() from the .py file fixed my problem.

1 Like