plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.
https://plotly.com/dash
MIT License
21.16k stars 2.04k forks source link

port forwarding does not work if use_reloader=True #1076

Open IvoLeist opened 4 years ago

IvoLeist commented 4 years ago

Describe your context I am used to developing my dash apps remotely where I use port forwarding from a linux to a win10 machine. When building a new one I realized the odd behaviour that omitting use_reloader leads to a never stop loading dash app on the local system but if I set use_reloader=False it works as expected.

Describe the bug

It is not really a bug since I already found a solution for it but if you want to reproduce it: Below does not work:

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

Below does work:

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

Port forwarding in both cases

Remote: python3 app.py & ssh -NfR 8050:localhost:8050 user@system
Local: python3 app.py & ssh -NfL 8050:localhost:8050 user@system

Expected behavior Not sure what use_reloader does explicitly but I just would expect that the port forwarding should not be affected by it? On the remote system's browser the app works despite not setting use_reloader=False

Screenshots I guess it would not help on the local system's browser there is just a spinning loading wheel in the taskbar and a completely white screen.

If this is kinda an expected behavior feel free to close this issue. I just wanted to share it because I was frustrated for over an hour why the new app just did not show up on my local system. Till code comparisons with my working app finally resolved it. So maybe this issue helps someone in the future why the port forwarding does not work.

Best, Ivo

djeinstine commented 2 years ago

I have the same issue. I don't know if you've found a way to get code reloading to work, but it has to do with the following (from dash documentation):

A caveat of Code Reloading is that your app code is run twice when starting: once to start the parent process and another time to run the child process that gets reloaded.

So if you have multiple instances of an ssh tunnel, your code will cause an error trying to open 2 tunnels using the same port at the same time.