9

I'm getting an error when trying to run a simple dashboard using Dash. I'm using Spyder with Python 3.4. I've pip installed dash, dash_core_components, dash_html_compenents..

My code:

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

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

This was taken right from Dash/Plotly website tutorial

I get the following error:

 * Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
 * Restarting with stat
C:\Users\mwolfe\AppData\Local\Continuum\anaconda3\envs\py34\lib\site-packages\IPython\core\interactiveshell.py:2889: UserWarning:

To exit: use 'exit', 'quit', or Ctrl-D.

An exception has occurred, use %tb to see the full traceback.

SystemExit: 1

When I go to http://127.0.0.1:8050/ to try to view the example dashboard It won't load.

I've tried this in order to fix the issue, but haven't been able to get that to work.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Matt W.
  • 3,692
  • 2
  • 23
  • 46
  • Have you tried to see the full traceback? – Jacobian Mar 19 '18 at 19:33
  • 1
    (*Spyder maintainer here*) Please open a bug in our [issues tracker](https://github.com/spyder-ide/spyder/issues) so we can try to fix/improve this in our side. I know why it happens, but I don't how Dash is generating this error. – Carlos Cordoba Mar 19 '18 at 22:24
  • If this is stunting your development you may want to try running your dash app from the command line. Also, per chance it helps, I documented my experience building a dash app (and deploying to Heroku) [here](https://stackoverflow.com/a/47949174/3491991) – zelusp Mar 26 '18 at 19:00
  • 1
    Try setting Debug to False. It worked for me. – ScarletAndGray Apr 26 '18 at 21:37
  • @ScarletAndGray Spyder gets hung up when i put debug= False – Tinkinc Dec 05 '18 at 14:06
  • Maybe this got fixed in last few months, so in case anyone still having trouble. Setting Debug to False does indeed allow the tutorial example to display on Spyder 3.3.6 – Tunneller Apr 26 '20 at 01:07

2 Answers2

9

Update on Pechi's answer: now setting debug=False works inside Jupyter Notebook as well. I tested Matt's code in there and the URL works fine.

However, I think the problem is mainly with the use_reloader. You have to set that to False in Jupyter Notebook (according to Plotly documentation). So, this also works in notebook for me:

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

app = dash.Dash()

app.layout = html.Div(
html.H1(children="Hello000")
)
if __name__ == '__main__':
    app.run_server(debug=True, use_reloader=False). <---- Here

Also, make sure any previous app you have initiated is stopped already (ctrl + c or simply use the square button in notebook (or press 'i' twice on your keyboard) for stopping the execution).

pegah
  • 791
  • 8
  • 15
3

Setting debug=False does solve the problem, but not with Jupyter notebook and Spyder. The code goes into limbo when executed with notebook/spyder.

Change your code to debug=False and execute it in PyQt console that comes with Anaconda Navigator. It works.

Robson
  • 813
  • 5
  • 21
  • 40
Pechi
  • 151
  • 1
  • 6