Hi!
I’m creating a dash that I need to run in 2 different computers. In one of them is working all fine, in the other computer I tried to copy everything to run it but a message pops up:
Serving Flask app "myDashApp" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
I think I did exactly the same in both computers, but I don’t manage to run the code in the second computer at it does in the first. Do you have any idea of what I’m doing wrong?
Any version of app.run_server() should produce this warning, Dash is using a library called Flask and calling the .run() method on the Flask app which by default uses the werkzeug development server which is similar to Python’s http.server. While the a great library for quickly running web-server in development it is not tested for security or performance.
So what do you use instead? Popular choices are gunicorn and uWSGI .
I personally use gunicorn, so in my Dash index.py (which is the script that launches my Dash app, otherwise replace index with the name of your script) I have the following code:
if __name__ == '__main__':
# For Development only, otherwise use gunicorn or uwsgi to launch, e.g.
# gunicorn -b 0.0.0.0:8050 index:app.server
app.run_server(
port=8050,
host='0.0.0.0'
)
And so I have gunicorn installed and when I want to launch via gunicorn I do the following:
gunicorn -b 0.0.0.0:8050 index:app.server
This, among other things, produces better performance.
Finally you may want to hook gunicorn/uWSGI to Apache, nginx, or IIS, these web servers lots of production stability options, directly serving and caching your resources, timeout options, and many other other things.
Hi Damian, thank you for the answer! I’m trying to do it, but I seem to have a problem with gunicorn. It warns me that he cannot import the module fcntl. I saw that might be related because I’m trying to run it on windows. I also tried with waitress but it’s still not working:
I’ve never used waitress-serve but assuming dash_alphav6 is your python file (i.e. dash_alphav6.py) and app is your dash.Dash() then you will probably need to use the command:
waitress-serve dash_alphav6:app.server
As app.server is the underlying Flask server these frameworks usually need.
@Damian,
I am new to Python and just installed Dash and plotly. I took the simplest app example from the user documentation and tried to run it in Spyder. Initially I was getting the same error/warning to not use Debug mode. I then installed gunicorn after I looked at this post. However, I am unable to follow where exactly the gunicorn call goes. Any help/guidance is greatly appreciated.
If you’re not actually trying to deploy an app into production, then it’ll be easier to avoid gunicorn. Instead of running in Spyder, try running on the command line. ie:
@nedned,
Thank you for your response. I tried to run the app in my Anaconda Prompt using the following command
python app.py
[quote=“nedned, post:7, topic:21348, full:true”]
If you’re not actually trying to deploy an app into production, then it’ll be easier to avoid gunicorn. Instead of running in Spyder, try running on the command line. ie:
$ python your_app.py
It does not really yield anything in my browser, so I am not sure what to expect.
Maybe turn debug mode back on to start with. Can you be more specific about what you’re seeing in the browser when you load http://localhost:8050? Is anything displayed at all?
Hi guys! What @nedned is saying is true, you need to open http://0.0.0.0:8050/ in the web browser. @UdayGuntupalli but instead of running in the CMD:python main.py I recommend you to install waitress and run waitress-serve main:app.server
But note that running with waitress (ie as a WSGI app) will turn result in debug mode being turned off (unless you set the relevant environment variable to turn it on) so you may want to do that in production, while sticking to the dev server approach when developing.
I am trying to deploy my program in production mode with waitress, but I am getting an issue of not being able to load again. Basically, when I run it one, it works, then when I try to run it again, it doesn’t.
I think it’s because I am using waitress wrong in my python program. I basically import waitress and use serve(app). Is this wrong? How should I be using waitress? Any sample code would be greatly appreciated as well!
Hi!
I don’t know how are you doing it. I guess that you are not clossing waitress once you launch it for the first time. In my case I’ve build a *.bat file and I’m running the following code:
What I didn’t manage yet is to continue the development in other computer running the debug mode. As @nedned says, the it turns off. So waitress is just working to run your dash propperly, but I don’t think it’s good enough to do development.
Is waitress used wtihin the python code typically as a package? There’s little documentation explaining what waitress is and how to use it in python. Thanks
Also, when I use waitress.serve in the python program, it doesn’t automatically kill the connection when I stop running the program. To kill the connection, I manually go to the CMD and kill the connection. This is not a thing with Flask because Ctrl + C kills the connection. Do you know how I can go about this?
from waitress import serve
#program for python
serve(app.server,host=host,port=1001) #this connects with the server
I have also tried:
server = create_server(app)
server.run()
But this doesn’t work as well. Any help will be appreciated!
Could you please illustrate what should be our imports in the index.py.
Should we be importing the “app” in the app = dash.Dash(server=server) or should we be importing “server” in the server = flask.Flask(__name__)
I have done the below:
I am developing an application using dash and want to host it using Gunicorn on linux platform (RHEL).
The following is how I have deployed it.
my dash application :
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
import flask
<data_frame definitions>
server = flask.Flask(__name__)
app = dash.Dash(server=server)
<app.layout>
<Call backs>
## at the end
if __name__ == '__main__':
app.run_server()
Created an index.py for Gunicorn
from MyPoC.Package import server as application
application
When I use the below command, I see no errors on the screen, but yet I can’t reach the application from the browser.