I have what is probably an extremely basic question, I am new to plotly/dash and struggling to understand the plotly/dash/flask interplay behind the scenes.
I have a python script that creates multiple Dash Apps on localhost. Each App is intended to be a single browser page (microsoft edge) full screen plot (plotly.graphics_objects 3d scatter plot) of various data.
There is one “central” browser page, that, when clicked, opens the other browser pages via plotly/dash callbacks and the webrowser.open_new_tab() method.
All of this is functioning perfectly except for the fact that after 7 dash apps are open, the callbacks in the “central” browser tab stop working, so no new browser tabs can be opened by the script via webrowser.open_new_tab(). No exceptions are thrown. The callbacks simply stop calling back it seems.
My question is, is there some kind of limit on how many dash apps can be running on a localhost simultaneously? At first I thought it was a port issue, due to selecting ports that aren’t open. But I found some code to only use port numbers that are open. The number of apps (and by extension, browser tabs) allowed to open is always 7, no matter what port numbers are used.
Welcome to the community!
This is an interesting way to go about things, it sounds like you should be instead using pages and having navigation to your individual charts as their own page.
If you are set on having different apps, you can also load different apps into a singular app and have it run those too. At least, that’s my understanding of how the docs for AG Grid are ran. @AnnMarieW would know more.
Hi, most likely this has also to do with the inactivity mechanisms of your browser, in order to save resources. It will be either throttled or become inactive all together (as you experience?. You can disable this or tune but as @jinnyzor mentioned, it would be far better to use pages.
@mjmass3 are your different Dash apps running within the same Python process and therefore all being hosted at the same localhost port? Or are they all running in separate processes, across multiple ports (eg http://localhost:8050/, http://localhost:8051/, http://localhost:8052/)?
If you are running them in the same Python process, then that may well be your problem. There is a fundamental limitation of Dash that you can only have once
Dash instance safely running inside a process. This is because Dash uses global state within the
dash module to manage callbacks defined with
dash.callback as well as for managing page data when using Dash Pages.
I think there could be an improvement here for Dash to warn you when using multiple Dash instances, as unless you are aware of this limitation and avoid features that introduce global state, there’s a good chance your app will break in mysterious ways without you knowing what’s going on.
Thank you for your answer! I was afraid that I was probably using Dash in an unintended way. I was initially excited about how easy it was to use the callbacks with multiple apps instead of different pages in an app. But this limit is a dealbreaker, so I will probably have to look into how to do multiple pages instead, as you suggest.
Thank you for your answer! They are running on separate ports on the localhost. But after 7 ports, no more will open. So as others have suggested, I will look into pages instead of separate apps.
Thank you for your answer! As you and others have suggested, I will look into pages instead of separate apps.
Ah right. That does sound a little peculiar. Moving to Pages may well be a more scalable solution.
If you did want to try to diagnose the existing problem, I’d suggest:
- running your apps with
debug=False (if not already), in case the hot reloader running multiple times is causing some kind of resource constraint
- opening up the network tab of the browser dev tools and then replicating the callback issue. if there is a problem at the request level of the callback, it tends to popup there as an error