pythondockerenvironment-variablesplotly-dashjupyter-lab

Why is Dash ignoring the HOST environment variable?


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.


Solution

  • Dash deliberately ignores HOST whenever it detects that it is running inside a Conda-managed environment (CONDA_PREFIX is in os.environ).
    This guard was added while fixing #3069 because some Conda activators export an invalid host name (e.g. x86_64-conda-linux-gnu), which breaks Flask’s socket binding.

    https://github.com/plotly/dash/issues/3069
    https://github.com/plotly/dash/pull/3130