从Jupyter Notebook运行破折号

时间:2019-04-11 03:25:13

标签: python jupyter-notebook

我正在尝试在Jupyter Notebook中运行破折号,但该应用程序未启动。我得到SystemExit:1错误。请帮助。我不是要在笔记本中运行而是要启动Web应用程序。如果我使用app.py文件,该文件可以运行,但是为什么我无法通过jupyter Notebook运行?

'''
import dash
import dash_cytoscape as cyto
import dash_html_components as html

app = dash.Dash(__name__)
app.layout = html.Div([
    cyto.Cytoscape(
        id='cytoscape',
        elements=[
            {'data': {'id': 'one', 'label': 'Node 1'}, 'position': {'x': 50, 'y': 50}},
            {'data': {'id': 'two', 'label': 'Node 2'}, 'position': {'x': 200, 'y': 200}},
            {'data': {'source': 'one', 'target': 'two','label': 'Node 1 to 2'}}
        ],
        layout={'name': 'preset'}
    )
])

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

我收到此错误:

Running on http://127.0.0.1:5001/
Running on http://127.0.0.1:5001/
Debugger PIN: 699-998-824
Debugger PIN: 699-998-824
 * Serving Flask app "__main__" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
An exception has occurred, use %tb to see the full traceback.

SystemExit: 1


/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py:3275: UserWarning:

To exit: use 'exit', 'quit', or Ctrl-D.
此烧瓶问题的

%tb:

Flask issue

1 个答案:

答案 0 :(得分:0)

@idontcare您必须更改几行才能在jupyter Notebook中运行此代码。首先使用

安装jupyter plotly破折号

[pip install jupyter-plotly-dash] 此安装中的Django需要通过安装进行设置 [pip install -U django-plotly-dash == 0.9.8]。

然后,jupyter-plotly-dash安装随附的破折号包含一个错误,需要降级至0.38.0。你可以用 [pip install dash == 0.38.0]

查看更新的代码:

'''

from jupyter_plotly_dash import JupyterDash
import dash
import dash_cytoscape as cyto
import dash_html_components as html

app = JupyterDash('YourAppExample')

app.layout = html.Div([
    cyto.Cytoscape(
        id='cytoscape',
        elements=[
            {'data': {'id': 'one', 'label': 'Node 1'}, 'position': {'x': 50, 'y': 50}},
            {'data': {'id': 'two', 'label': 'Node 2'}, 'position': {'x': 200, 'y': 200}},
            {'data': {'source': 'one', 'target': 'two','label': 'Node 1 to 2'}}
        ],
        layout={'name': 'preset'}
    )
])

app