简体   繁体   中英

Python Dash web-app raises Internal Server Error

Trying to deploy a Dash app on a Ubuntu 18.04 server. Any dash app raises an Internal Server Error. Any simple flask app does not. I managed to narrow down the problem by importing dash-core components or dash-html-components in a Flask app script without actually using them. This causes the problem. Apparently importing these packages is enough to throw the server error.

All dash packages have been properly installed with pip. I'm using apache2 and mod_wsgi to publish the app.

Edit : The above bugtesting was wrong, as dash-core-components should be written dash_core_components.

Edit2 : I am retracting the first edit. I can finally conclude that importing dash_html_components in a Flask app (just for testing) raises a server error.

This works:

from flask import Flask
import sys

app = Flask(__name__)

@app.route('/')
def homepage():
    return "Hello"

if __name__ == "__main__":
    app.run()

This throws an Internal Server Error:

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

app.layout = html.Div(children=['hello'])

server = app.server

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

Based on the explanation above, I conclude that dash_html_components causes the error. Is there any explanation for this?

I have not tried deploying a dash app on a Ubuntu 18.04 server, but I have successfully deployed on heroku with a standalone WSGI server (gunicorn). As for your server error, I'm not quite sure where it could be originating from (maybe python runtime version?). One thing you should try is to use flask to create the server, and then specify the server when creating the dash app:

import flask
import dash

server = flask.Flask(__name__)
app = dash.Dash(__name__, server=server)

If you're desperately trying to deploy your app, you can temporarily use heroku, they offer a very simple way to deploy flask applications. One caveat, make sure you are using python2 runtime version rather than python3!

For your convenience, here is the plotly docs on deploying dash applications. There is a simple heroku deployment example https://dash.plot.ly/deployment

Okay. In my testing, a Flask app worked just fine. The same Flask app with import dash or import dash_core_components randomly thrown in worked fine as well. As soon as I threw in import dash_html_components , I got a server error. All dash packages were properly installed with pip, so I don't know why merely importing the html components would cause a server error.

I fixed my problem simply by doing a hard reset of the Ubuntu 18.04 server, going through all the steps again, installing python3.6, pip3.6, apache2, wsgi and the dash packages. This time around, dash apps do not raise a server error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM