DASH_DEBUG environment variable not used when running app with gunicorn

I’m deploying my app to three different environments (test, acceptance, production). Depending on the environment, the Docker container running the app has different values for the DASH_DEBUG environment variable.
It seems this value is not recognised when launching the app with gunicorn.

Testing locally, this issue is confirmed. First I set the environment variable: export DASH_DEBUG='true'.
Then if I do uv run app.py the app displays the debug interface.
However, if I do uv run gunicorn --bind 0.0.0.0:8050 app:server the app does not display the debug interface.

How can I make it so the environment variable is recognised when launching with gunicorn?

Relevant code snippets:

import dash

...

app = dash.Dash(title='app_title')
# For gunicorn
server = app.server

...

if __name__ == "__main__":
    app.run(host="0.0.0.0")

The fix is to call app.enable_dev_tools(). This will read environment variables as desired. E.g.:

import dash

...

app = dash.Dash(title='app_title')
# For gunicorn
app.enable_dev_tools()
server = app.server

...

if __name__ == "__main__":
    app.run(host="0.0.0.0")
1 Like

@svdl

Glad you figured it out, gunicorn runs the server directly, that’s why the variables were not read.

Thank you for following up and posting your solution. :slight_smile:

1 Like