Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Not Found: /_dash-dependencies, /_dash-routes

So I have created a example dash app in Django, but when I run the project, it says:

[16/Nov/2017 14:23:56] "GET /app/ HTTP/1.1" 200 1565
Not Found: /_dash-layout
Not Found: /_dash-dependencies
[16/Nov/2017 14:23:57] "GET /_dash-layout HTTP/1.1" 404 2188
[16/Nov/2017 14:23:57] "GET /_dash-dependencies HTTP/1.1" 404 2206
Not Found: /_dash-routes
[16/Nov/2017 14:23:57] "GET /_dash-routes HTTP/1.1" 404 2188

Here is dashboard.py:
from random import randint

import dash
import dash_core_components as dcc
import dash_html_components as dhc


def dispatcher(request):
    '''
    Main function
    @param request: Request object
    '''

    app = _create_app()
    params = {
        'data': request.body,
        'method': request.method,
        'content_type': request.content_type
    }
    with app.server.test_request_context(request.path, **params):
        app.server.preprocess_request()
        try:
            response = app.server.full_dispatch_request()
        except Exception as e:
            response = app.server.make_response(app.server.handle_exception(e))
        return response.get_data()


def _create_app():
    ''' Creates dash application '''

    app = dash.Dash(csrf_protect=False)
    # app.config.update(
    #     {'routes_pathname_prefix': '/', 'routes_pathname_prefix': '/app/'}
    # )
    app.layout = dhc.Div(children=[
        dcc.Graph(
            id='main-graph',
            figure={
                'data': [{
                    'name': 'Some name',
                    'mode': 'line',
                    'line': {
                        'color': 'rgb(0, 0, 0)',
                        'opacity': 1
                    },
                    'type': 'scatter',
                    'x': [randint(1, 100) for x in range(0, 20)],
                    'y': [randint(1, 100) for x in range(0, 20)]
                }],
                'layout': {
                    'autosize': True,
                    'scene': {
                        'bgcolor': 'rgb(255, 255, 255)',
                        'xaxis': {
                            'titlefont': {'color': 'rgb(0, 0, 0)'},
                            'title': 'X-AXIS',
                            'color': 'rgb(0, 0, 0)'
                        },
                        'yaxis': {
                            'titlefont': {'color': 'rgb(0, 0, 0)'},
                            'title': 'Y-AXIS',
                            'color': 'rgb(0, 0, 0)'
                        }
                    }
                }
            }
        )
    ])
    return app
if __name__ == '__main__':
    app = _create_app()
    app.run_server()

and here is the views.py:

def index(request, **kwargs):
    ''' '''
    return HttpResponse(app.dashboard.dispatcher(request))

This is a somewhat non-standard setup, so you might need to provide some more context to what you’re trying to achieve/why you’re doing it this way.

Is there a reason why you’re creating you’re own index route (at least that what it looks like you’re doing)? Dash has its own index route that this will probably clash with. If you’re running this script from the command line, then you’ll also be creating two separate Dash instances—one in the if name == ‘main’: and one in the dispatcher— which doesn’t seem like it’s what you want.

Basically, I am trying to add my dash app into Django, I am not running this script, but running Django project by python manage.py runserver, so if name==‘main’ will never be executed. But it shows me that those three dependency are not found.

So am I gathering right that you’re trying to somehow pass requests from some other interface into the Dash app’s Flask server? Two things worth considering, is that mechanism actually going to work? I have no experience here, possibly you have more than I do, but it’s not immediately clear to me that it will.

Secondly, does this setup actually wind up running the Flask server instance at any point? It looks like it might not. Which would certainly explain those issues.