尝试在Spyder IPython控制台中初始化Dash时出错 [英] Error Trying to initialize Dash in Spyder IPython Console

查看:361
本文介绍了尝试在Spyder IPython控制台中初始化Dash时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用Dash运行简单的仪表板时出现错误.我正在将Spyder与Python 3.4配合使用.我已经pip installed dash, dash_core_components, dash_html_compenents ..

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..

我的代码:

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)

这是直接从 Dash/Plotly网站教程

我收到以下错误:

 * 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

当我转到http://127.0.0.1:8050/尝试查看示例仪表板时,它将不会加载.

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.

推荐答案

更新Pechi的答案:现在,在Jupyter Notebook中也可以设置debug = False.我在那里测试了Matt的代码,URL正常工作.

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.

但是,我认为问题主要出在use_reloader上.您必须在Jupyter Notebook中将其设置为False(根据Plotly文档).因此,这对我也适用于笔记本:

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

此外,请确保您已启动的任何先前应用已被停止(Ctrl + C或只是使用笔记本中的方形按钮(或在键盘上按两次"i")以停止执行).

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).

这篇关于尝试在Spyder IPython控制台中初始化Dash时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆