1

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.

4
  • 1
    Are you using conda? It seems Dash is ignoring the HOST variable if CONDA_PREFIX is set. Commented Jul 8 at 7:12
  • @Amadan yes I am, and I tried removing the CONDA_PREFIX variable with del os.environ["CONDA_PREFIX"]: it works fine! Is there a cleaner solution? Commented Jul 8 at 7:27
  • Honestly, no idea, first time I heard about Dash is your post. But if you're just going to use the HOST envvar, you could explicitly get it and pass it into run; seems clean enough to me. Commented Jul 8 at 9:01
  • @Amadan Ok, this is fine with me. If you want to make an answer, I'll accept it Commented Jul 8 at 9:30

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Just adding that the solution for me was to delete the CONDA_PREFIX variable before importing dash: del os.environ["CONDA_PREFIX"]. I don't fully understand the linked issue though and therefore note sure of the side effects this solution might cause...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.