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!

Flask Endpoint Error

Hi All,

Firstly, thanks everyone for the great work. We are testing Dash and we had it up and running but started receiving this error after our upgrade to Dash 0.18.1.
AssertionError: View function mapping is overwriting an existing endpoint function: serve_layout

Code that replicates from standard example below. Thanks for your help!

Trace:

Traceback (most recent call last):
  File "/home/joe/pycharm/helpers/pydev/pydevd.py", line 1585, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/joe/pycharm/helpers/pydev/pydevd.py", line 1015, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/joe/pycharm/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/joe/PycharmProjects/dash_test/run.py", line 4, in <module>
    import app2
  File "/home/joe/PycharmProjects/dash_test/app2.py", line 11, in <module>
    app = dash.Dash(name='app2', server=server, url_base_pathname='/app2' )
  File "/home/joe/.virtualenvs/dash_web_analytics/src/dash/dash/dash.py", line 73, in __init__
    view_func=self.serve_layout)
  File "/home/joe/.virtualenvs/dash_web_analytics/lib/python3.5/site-packages/flask/app.py", line 64, in wrapper_func
    return f(self, *args, **kwargs)
  File "/home/joe/.virtualenvs/dash_web_analytics/lib/python3.5/site-packages/flask/app.py", line 1051, in add_url_rule
    'existing endpoint function: %s' % endpoint)
AssertionError: View function mapping is overwriting an existing endpoint function: serve_layout

run.py

from server import server

import app1
import app2

if __name__ == '__main__':

    server.run(debug=True)

server.py

from flask import Flask
server = Flask(__name__)
server.secret_key ='asdfasefasedfaswefwasefasdf'

app1.py

import dash
from dash.dependencies import Input, Output
import dash_html_components as html
import dash_core_components as dcc

from server import server

app = dash.Dash(name='app1', server=server, url_base_pathname='/app1' )

app.layout = html.Div([
    html.H3('App 1'),
    dcc.Dropdown(
        id='app-1-dropdown',
        options=[
            {'label': 'App 1 - {}'.format(i), 'value': i} for i in [
                'NYC', 'MTL', 'LA'
            ]
        ],
        value='NYC'
    ),
    html.Div(id='app-1-display-value'),
    dcc.Link('Go to App 2', href='/app2')
])


@app.callback(
    Output('app-1-display-value', 'children'),
    [Input('app-1-dropdown', 'value')])
def display_value(value):
    return 'You have selected "{}"'.format(value)

app2.py

from dash.dependencies import Input, Output
import dash
import dash_html_components as html
import dash_core_components as dcc


from server import server



app = dash.Dash(name='app2', server=server, url_base_pathname='/app2' )

app.layout = html.Div([
    html.H3('App 2'),
    dcc.Dropdown(
        id='app-2-dropdown',
        options=[
            {'label': 'App 2 - {}'.format(i), 'value': i} for i in [
                'NYC', 'MTL', 'LA'
            ]
        ],
        value='NYC'
    ),
    html.Div(id='app-2-display-value'),
    dcc.Link('Go to App 1', href='/app1')
])


@app.callback(
    Output('app-2-display-value', 'children'),
    [Input('app-2-dropdown', 'value')])
def display_value(value):
    return 'You have selected "{}"'.format(value)

reqs.txt

certifi==2017.7.27.1
chardet==3.0.4
click==6.7
dash==0.18.1
dash-core-components==0.12.4
dash-html-components==0.7.0
dash-renderer==0.9.0
decorator==4.1.2
Flask==0.12.2
Flask-Compress==1.4.0
Flask-SeaSurf==0.2.2
gevent==1.2.2
greenlet==0.4.12
idna==2.6
ipython-genutils==0.2.0
itsdangerous==0.24
Jinja2==2.9.6
jsonschema==2.6.0
jupyter-core==4.3.0
MarkupSafe==1.0
nbformat==4.4.0
numpy==1.13.1
pandas==0.20.3
pandas-datareader==0.5.0
plotly==2.0.15
PyMySQL==0.7.11
python-dateutil==2.6.1
pytz==2017.2
requests==2.18.4
requests-file==1.4.2
requests-ftp==0.3.1
site==0.0.1
six==1.10.0
SQLAlchemy==1.1.13
traitlets==4.3.2
urllib3==1.22
uWSGI==2.0.15
Werkzeug==0.12.2

What version of the dash components are you using? The recommended versions are list below:
pip install dash==0.18.1 # The core dash backend
pip install dash-renderer==0.9.0 # The dash front-end
pip install dash-html-components==0.7.0 # HTML components
pip install dash-core-components==0.12.4 # Supercharged components
pip install plotly --upgrade # Plotly graphing library used in examples

Refer to https://plot.ly/dash/installation for more details

Hi Kfyao,

Yes. Good question. Edited my post with requirements.txt. Here is what I am running:
dash==0.18.1
dash-core-components==0.12.4
dash-html-components==0.7.0
dash-renderer==0.9.0
plotly==2.0.15

The error is produced with these versions.

Its also interesting to note that if I comment out one of the app imports (so only import a single app for serving) the applications works great.

This works:
run.py

from server import server

import app1
#import app2

if __name__ == '__main__':

    server.run(debug=True)

You may want to check out this https://github.com/plotly/dash/pull/70/commits/b58ca7f6fb5ae52cd7289dc28ae2437afc71d39b

It seems this patch regarding multiple app has not been released to public

Hmm. So I saw that this patch was merged with master and so I pulled the latest dash 0.18.2 but now have other issues… So now no matter what url route is passed to browser dash renders the last app that was imported in the run.py file.

Not sure if the Flask approach is the way to go with Dash.

thanks

Thanks for reporting @joe! I’m working on a fix today.

I have published a preliminary fix in the pre-release channel: pip install dash==0.18.3rc1. Let me know if this works for you!

That worked.

Thanks for all your hard work. Very impressive project.