✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Routing issues Dash + Flask

I have two separate apps:

  1. Flask app:
    flask_app = connexion.App(__name__)

  2. Dash app:
    external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]
    dash_app = dash.Dash(name, external_stylesheets=external_stylesheets)
    dash_app.layout = html.Div([html.H1(‘This is a base header’)])

Also, I’m working with both of them:

app = DispatcherMiddleware(flask_app, {
            '/reports': dash_app.server
        })

To run my app I’m writing:
run_simple(
hostname=“localhost”,
port=config[“port”],
application=app,
threaded=True,
use_debugger=True
)

More or less it’s OK, but…

When I’m sending GET request to:
http://localhost:8888/reports

I’m getting an error:
[2019-01-02 20:21:01,131] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File “/home/user/app/venv/local/lib/python2.7/site-packages/flask/app.py”, line 2292, in wsgi_app
response = self.full_dispatch_request()
File “/home/user/app/venv/local/lib/python2.7/site-packages/flask/app.py”, line 1808, in full_dispatch_request
self.try_trigger_before_first_request_functions()
File “/home/user/app/venv/local/lib/python2.7/site-packages/flask/app.py”, line 1855, in try_trigger_before_first_request_functions
func()
File “/home/user/app/venv/local/lib/python2.7/site-packages/dash/dash.py”, line 994, in _setup_server
self._validate_layout()
File “/home/user/app/venv/local/lib/python2.7/site-packages/dash/dash.py”, line 982, in _validate_layout
for component in to_validate.traverse():
AttributeError: ‘Response’ object has no attribute ‘traverse’
127.0.0.1 - - [02/Jan/2019 20:21:01] “GET /reports/ HTTP/1.1” 500 -

I was trying to play with url_base_pathname, but with no luck ;(

Hi @pivanchy,

Could you change the category of your post from API/Python to Dash? You’ll probably have better luck over there. Thanks!

-Jon

When you use DispatcherMiddleware to embed a Dash app, you need to modify the requests_pathname_prefix to contain the full prefix including the mount point. So I would try this:

dash_app = dash.Dash( __name__, requests_pathname_prefix='/reports/')

However I haven’t seen that particular error you’re encountering as being associated with omitting this step. If you’re still experiencing issues, could you post a complete, minimal example of the issue?