Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Can I use Dash Plotly in Production environment

Dash Plotly can quickly help me to build Factsheet website.
I am not sure about its performance. Can we scale out the application? For example, launch more instances of this web app so that we can handle more requests.

I am currently employed in a production company and have made a Dash app which is showing an overview of our production to our production; (current machine status, current production, planned production etc etc.), and an app which includes some analysis of our production to our engineers and production officers.
Worth to mention, the app is updating either when a user is selection something new from dropdowns or tabs, or when they are looking at the production overview which updates every 10 seconds using dcc.Interval component.

Let me share my experience. :man_technologist:

I am using Flask to deploy the app. There are some examples on how to do this in the Dash documentation, let me know if you are unable to find it yourself.
My apps are located on a virtual windows server in the company and I found that the server was struggling to keep up when the apps where running and users where accessing whatever I had made (mainly the CPU usage of the server was juggling around 80-100% usage, which is a lot for a rather simple Dash webapp.

As you deploy stuff through Flask you will get a message in your terminal:

What I thought of this message was something like “Oh, we need to use something mightier/smarter than Flask to handle requests from multiple users on the apps”

The solution I found to this was to install an IIS service on my virtual server and let it handle the web apps. How to do this is a little technical and I am far from an expert on this topic, but I somehow made it work.

This drastically made the CPU usage on the server drop and I suppose this is due to a smarter request handling (a better waitress/server) of my apps.

Final remark: I am still not 100% sure if I still need to “bottle up my app in a Flask” before I deploy through my IIS service, I will look into this Soon™ when I have time (prioritizing time and company stuff, blah blah blah…).

I hope this will help you judge whether or not you should use plotly Dash. :slightly_smiling_face:

5 Likes

A “:heart:” brought me back to this thread, so here is an update.

There is no need to use Flask when you deploy your Dash app using IIS, I am currently serving through the library “waitress” which can handle the requests (serve requests) coming from the WSGI on my IIS.
Switching from Flask to waitress with wsgi and remembering to set debug=False dramatically improved the responsiveness of my application in our production environment. :man_technologist:

3 Likes

Hi @Blaceus : can you please elaborate on how you use waitress with IIS? I successfully managed to deploy my app using IIS, but it is extremely slow. Using waitress is considerably faster, but without the bells and whistles of IIS.

Thanks,
Vivek

you can use gunicorn deploy flask in your prod env.

1 Like

Hi @jimmybow : My workplace is restricted to using Windows Server :confused: . This would be my very first deployment, so not really experienced with using any web servers.

Thanks,
Vivek

Hello hello

Essentially what I’m doing is running the Dash app like this:
In my app.py:

app = dash.Dash(__name__)
server = app.server
app.config['suppress_callback_exceptions']=True

if __name__ == '__main__':
	app.run_server(debug=True)

My waitress script:

from waitress import serve
from app import server #so "app" is the name of my Dash script I want to serve

serve(server)

With this setup, if I want to launch my app, I have to run my waitress script (let’s say I have named this script server.py --> To launch my app, I need to python server.py and then everything works.
Hope it helps. :slight_smile:

1 Like

Great- thanks @Blaceus :slight_smile: :slight_smile: . I figured it out from your other comments. I then switched to serving using Docker and gunicorn, as it’s convenient to test the app in the local environment and expect similar behavior in the production environment.

1 Like

Hi Blaceus - I work at a manufacturing company in Austin, TX on a project that sounds extremely similar to how you’ve described your project. I’m building a Dash app for machine supervisors to monitor production and edit incorrect data readouts from the machines. It’s a multi-page app containing a thumbnail-based home page with connected pages specific to a selected machine. I’d be interested in comparing notes if you have time :smiley:

It depends on how many people visit the web site.

I build a management system using dash plotly.The maximum online user for this site is 100 people and it works normally.But the performance has dropped a little bit.

Hey,

I am also using waitress in the same way, but the program will not kill the connection once I run the program. I have to manually kill the connection through the CMD, but for Flask, I can just Ctrl + C. Otherwise, I cannot run any dashbaords, even reloading the same program. Is there a way to kill the connection without manually going to the command prompt? Thanks

I am not sure that I understand your question, but nevertheless…

When I am running my Dash app with Waitress, I can easily kill the application by clicking ctrl+c a few times in the prompt.
This was the same thing which worked for me as I had my app in Flask.

That is very interesting. What is the syntax of waitress within your python code?

In my program, I have:

from waitress import serve
#program
host = socket.gethostbyname(socket.gethostname())
serve(app.server,host=host,port=1001,threads=10)

I even tried to remove host and threads, but still the same result. Also, was edition of waitress are you using? I’ll just need to see if I need to upgrade or anything of that sort.

The CRTL + C prompt does not pop up like how it will from Flask and I am not too sure why

I have a dockerized version of dash that i deploy in an aws cluster which is escalable. no problems so far

My waitress script:

from waitress import serve
from dashboard_d4 import server

serve(server)

From my Dash app (dashboard_d4 from up above):

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


if __name__ == '__main__':
	app.run_server(debug=True)

I run my server script in a prompt with >python server.py
And I can cancel the application by selecting my prompt and hit ctrl+C.
I am using waitress version 1.1.0

@Blaceus Thanks for the help. I am actually running a multi-page dash application, so where would I out the sserve(server)? I am using the index/app/app_1/app_2 format format for running this multipage application (example: https://dash.plot.ly/urls).

I am not sure what you mean?

If you application works when you run it locally, you just need to find something to host it publicly if needed…

I have my application hosted through IIS on a windows server within my company where the IT administrator has opened up traffic on the local network to the IP:port I have chosen on the IIS.

One of my apps are using single URL, but multiple tabs.
The other is using multiple URL, single tab.

Hope this helps, somehow? :slightly_smiling_face:

Okay, so I figured out what was going on. When I wrote the program, I was running the program in my IDE instead of the command prompt. When I ran it from my command prompt, everything worked. Thanks for the help.

Hi, I have a question, i was able to run dash on waitress with your config above, but i dont need IIS at all (i was able to access the dash app from other pc in local network with the link waitress provided), can you show me how or where to find info to set up and config IIS with Waitress.
Thanks a lot :smiley:

I am trying to use waitress from within IIS. My dash app works great when run from the command line as described by Blaceus, But when i try access it through a site/app served by IIS I get at FastCGI process exceeded configured activity timeout. I am guessing I do not have IIS FastCGI configured correctly but I have been unable to figure it out.