Deploying dash app to internal network (with Redis Cache)

Hello,

I have deployed my first app to Heroku. But my company cannot use Heroku. I need to deploy to our internal server.
My dash app connects to Snowflake (cloud datawarehouse), Below official sample app connects to Snowflake and also use Redis Cache.

https://github.com/plotly/dash-sample-apps/blob/main/apps/dash-interest-rate/app.py

My question is:

  1. Which hardware/sofware I need in my internal network to deploy my app, for example windows 10 server will do?
  2. Redis Cache install

Thanks,
Parthib.

Since Dash is based on Flask, you can deploy Dash apps anywhere you can deploy a Flask app. Like most Python web apps, Flask uses WSGI , so in fact, you can deploy your Dash app anywhere you can deploy a WSGI app… which is a lot of places, from dedicated servers or cloud VMs running on either Linux or Windows, or cloud web app services like AWS Beanstalk and GCP App Engine.

I’d suggest working out what constraints you have first, then Googling for WSGI deployment strategies. If you’re running a Windows server, I hear that Waitress is a good option. You could look around for Waitress + Flask deployment tutorials.

But if it’s easy for you to spin up a Linux server, that could give you more flexibility. Especially if you’re hoping to run the redis installation of the same machine, as it looks like redis is only supported on Windows via WSL2.

4 Likes

I have deployed to Heroku with Redis server .
I will try with Waitress in our local server after POC done.
thank you so much

Our company decided to use linux server.
Please let me know what could be hardware software requirements for dash app which connects Snowflake cloud data warehouse.
Also, I would like to install Redis, any specific version or hardware needed for Redis?

Thank you

1 Like

My company suggest to use linux docker container. Is it possible to deploy both Dash app and Redis cache on docker container ?.

Hello @parthib,

Yes, using docker containers is possible.

I don’t think having two major processes in the same container is a good idea, as to me it makes more sense to have them separated for troubleshooting and updating to ease downtime.

Here is basic instructions for dash with docker:

Here is how you can run Redi using docker:

3 Likes

Hi Jinnyzor,

Excellent info. thank you for sharing. will go through it.
Have a nice day!

1 Like

Also, another thing you could look into is Proxmox for a hypervisor that can spin up containers and VMs on an older machine. :slight_smile:

sure. i shall check it.

1 Like

Hi Jinnyzor,

I followed below link to build docker file for my dash app.
https://towardsdatascience.com/dockerize-your-dash-app-1e155dd1cea3

need many config libraries…
but with Heroku , we just need procfile.
Is there any dash simple project template for dockerizing?

FYI

1 Like

Hello stu,

Managed to dockerize dash app, also configured Redis cache.

Below is the my python code:

os.environ["REDIS_URL"] = config("REDIS_URL", config("EXTERNAL_REDIS_URL"))
app = dash.Dash(__name__, meta_tags=[{"name": "viewport", "content": "width=device-width"}])
server = app.server
cache = Cache(
    app.server,
    config={"CACHE_TYPE": "redis", "CACHE_REDIS_URL": os.environ.get("REDIS_URL", "")},
)

EXTERNAL_REDIS_URL or REDIS_URL points to my Redis Cloud subscription as below:

redis://default:XaPAGfuJZXuVhuUyLP0dpmtuixA@redis-15219.c295.ap-southeast-1-1.ec2.cloud.redislabs.com:15219

But how to test Redis Cache working or not?.

You could use a basic background callback, that should be able to test it.

Below is my callback code:

 html.Div([
            html.P('Select Work Week', className='fix_label', style= {'color': 'white'}),
            dcc.Dropdown(id = 'work_week',
                         multi = False,
                         searchable= True,
                         clearable = True,
                         disabled = False,
                         style = {'display': True},
                         value = '50',
                         placeholder = 'Select Work Week',
                         options = [], className = 'dcc_compon'),
        ], className='one-third column', id = 'title3')
...........
@app.callback(Output('text1', 'children'),
              [Input('work_week','value')])
def update_graph(work_week):
    #Dispatched = df_work_order.groupby(['work_week1'])['wo_qty'].sum().reset_index()
    Dispatched_qty = Dispatched[(Dispatched['work_week1'] == int(work_week))]

    return [

        html.H6(children='Dispatched Qty',
                style={'textAlign': 'center',
                       'color': 'white'}),

        html.P((Dispatched_qty['wo_qty']),
               style={'textAlign': 'center',
                      'color': '#19AAE1',
                      'fontSize': 30,
                      'margin-top': '-10px'})

    ]



do I need to change above callback code to test Redis ?

You can try one of the example background callbacks here, make sure it’s setup to use Redis.