Setting Up and Running the App with a WSGI

Learn how to set up and execute Dash applications using Gunicorn, the WSGI server.

We have run our app using the python app.py command from the command line. Alternatively, we used the app.run_server method when running with jupyter_dash. We are going to do it now with Gunicorn, our WSGI server.

The command is slightly different from the previous one and is run with the following pattern:

gunicorn <app_module_name:server_name>

We have two main differences here. First, we only use the module name or the file name without the .py extension. Then, we add a colon, and then the server name. This is a simple variable that we have to define, and it can be done with one line of code, right after we define our top-level app variable, as follows:

app = dash.Dash(__name__)
server = app.server

Now that we have defined our sever as server, and assuming our app is in a file called app.py, we can run the app from the command line, as follows:

gunicorn app:server

That’s it for the WSGI server! Once that change has been made, we can go to the folder where our app is and run it with the preceding command. The following illustration shows the output we get when running our app with the gunicorn command:

Get hands-on with 1200+ tech skills courses.