簡體   English   中英

嘗試在 Spyder IPython 控制台中初始化 Dash 時出錯

[英]Error Trying to initialize Dash in Spyder IPython Console

嘗試使用 Dash 運行簡單的儀表板時出現錯誤。 我在 Python 3.4 中使用 Spyder。 我已經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/嘗試查看示例儀表板時,它不會加載。

我已經嘗試過這個來解決這個問題,但一直無法讓它發揮作用。

Pechi 的回答更新:現在設置 debug=False 也適用於 Jupyter Notebook。 我在那里測試了 Matt 的代碼,URL 工作正常。

但是,我認為問題主要出在 use_reloader 上。 您必須在 Jupyter Notebook 中將其設置為 False(根據 Plotly 文檔)。 所以,這也適用於我的筆記本:

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”兩次)來停止執行)。

設置debug=False確實解決了問題,但不適用於 Jupyter notebook 和 Spyder。 使用 notebook/spyder 執行時,代碼會陷入困境。

將您的代碼更改為debug=False並在Anaconda Navigator 附帶的PyQt 控制台執行它 它有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM