I have this minimal Dash app:
import os
import dash
from dash import html
app = dash.Dash(__name__)
app.layout = html.Div("Hello Dash!")
print(f'{os.environ["HOST"]=}')
app.run()
The environment variable HOST is set to 0.0.0.0. According to the Dash documentation, when the host parameter to the app.run method is not specified, the HOST variable should be used:
host
Host IP used to serve the application, default to "127.0.0.1" env: HOST
However, when I run the above code, Dash seems to ignore the HOST variable and runs on 127.0.0.1:
$ python dash_app_minimal.py
os.environ["HOST"]='0.0.0.0'
Dash is running on http://127.0.0.1:8080/
If I pass the host argument (app.run(host="0.0.0.0")), it works fine:
$ python dash_app_minimal.py
os.environ["HOST"]='0.0.0.0'
Dash is running on http://0.0.0.0:8080/
Note that the PORT variable is considered, as expected:
$ PORT=8888 python dash_app_minimal.py
os.environ["HOST"]='0.0.0.0'
Dash is running on http://127.0.0.1:8888/
Environment: Dash 3.1.1 with Python 3.12.11, running on JupyterLab 4.4.3, in a Docker container based on this image: quay.io/jupyter/r-notebook:hub-5.3.0. Kubernetes 1.28.
HOSTvariable ifCONDA_PREFIXis set.CONDA_PREFIXvariable withdel os.environ["CONDA_PREFIX"]: it works fine! Is there a cleaner solution?HOSTenvvar, you could explicitly get it and pass it intorun; seems clean enough to me.