How to deploy Dash App internally in local network?

Hello,

I am quite new to the topic of deploying and trying to understand how things work. I saw the deployment tutorial with heroku but such a hosting platform in so solution for me.

What we have is an internal network (not quite intranet) within my department. Now what I want is to deploy the Dash App to an self hosted server since we have a 24/7 running computer and I want to use this. But what is the order to deploy a Dash App? Is Docker used? Do I put the App in the Docker Container and then launch that Container? I just now the basics of Container and try to figure out what part Docker plays in deploying and for example where Apache Server comes in.

Many thanks in advance.

Hi @Gobrel ,

The first thing you should verify is whether the server you want to deploy on is reachable from all the computers that will be used to access the app (clients).

Using docker is not necessary but I would personally recommend it. What docker does is that it provides an isolated environment (a container) for your app. This is especially useful if you run multiple services (apps) on your server and these might have conflicting dependencies. Running each app in its own container prevents the apps from conflicting with each other.

In principle, deploying a dash app is the same thing as deploying a flask app since dash is built on top of flask. Perhaps you can search for something like “flask gunicorn docker tutorial”…

I remember I used this tutorial some time ago. Maybe you can start with that. Don’t worry about the parts related to Amazon Web Services.

The steps that you will need to do:

  1. Make sure your server is reachable by your intended clients.
  2. Setup gunicorn as a wsgi server for your dash app. Do you remember the line you get whenever you start your dash app?
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
    
    You use gunicorn to solve this.
  3. Write your Dockerfile.
  4. Build a docker image based on your Dockerfile.
  5. Get the image to your server. You can either build the image directly on the server or you can build it on another machine and then upload it to an image registry. The default registry is dockerhub. Dockerhub allows you to have one private repo (aka image) and multiple public repos. Once you upload your image to the registry, you can download it again from your server.
  6. Create a docker container from you docker image. Once you do that, you will have your app deployed on the server.

I hope this helps. If you have further questions, feel free to ask.

1 Like

You can have a look at this repo:

It is a simple dash app that is deployed using gunicorn and docker.

2 Likes

For anyone reading this old thread…

If your company seeks a bit of external help with deployment of dash apps both internally and for external access, I’m happy to help! Best is to reach out to me through linkedin.

Deploying a Dash app to a self-hosted server can be an effective way to make your application accessible to users on your internal network. Here’s a step-by-step guide on how to achieve this using Docker, along with some insights on the role of Apache.

1. Set Up Your Development Environment

Before you start, ensure you have the following installed on your server:

  • Python: Since Dash is built on top of Flask, you’ll need Python installed.
  • Docker: This allows you to containerize your app, making it easier to deploy and manage dependencies.

2. Create Your Dash App

Start by developing your Dash app locally. Ensure that it runs as expected. Your app’s structure typically looks like this:

my_dash_app/

├── app.py # Your main Dash app
├── requirements.txt # Dependencies
└── Dockerfile # Instructions for Docker


### 3. **Create a Dockerfile**

In the root of your project folder, create a file named `Dockerfile`. Here’s a simple example:

dockerfile

# Use the official Python image
FROM python:3.9

# Set the working directory
WORKDIR /app

# Copy the current directory contents into the container
COPY . .

# Install the required packages
RUN pip install --no-cache-dir -r requirements.txt

# Expose the port your Dash app runs on
EXPOSE 8050

# Command to run your app
CMD ["python", "app.py"]