2

Working with Python Dash and have it working from local host, but when attempt to deploy to my python app server, I have issues.

When I keep the app as just Flask it works with this code:

from flask import Flask
import dash

app = Flask(__name__)

@app.route("/")
def hello():
     return "Hello World!"

When I try to pass the server to the Dash instance (when according to Dash docs is acceptable, I receive the error). Here is the code

from flask import Flask
import dash

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

@app.route("/")
def hello():
    return "Hello World!"


 I receiving the error:

AttributeError: 'Dash' object has no attribute 'route'
2
  • I don't know anything about Dash. Where in the docs does it say you can do this? Commented Nov 4, 2018 at 21:13
  • dash.plot.ly/deployment Commented Nov 4, 2018 at 21:21

2 Answers 2

4

The docs don't say what you think they do. app is the Dash instance, not the Flask one - that is available via the server variable, so you can call route on that.

@server.route("/")
def hello():
     return "Hello World!"
Sign up to request clarification or add additional context in comments.

1 Comment

I tried that exact thing as well, did not solve the issue.
2

As Daniel Roseman said, you must use server.route instead of app.route.

However, Dash registers itself to serve the path /, overwriting your route.

Other paths not used by Dash work as expected, e.g.:

@server.route('/hello-world')
def hello():
     return "Hello World!"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.