jupyter noteb中的跑步冲刺

2024-06-29 00:02:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着在jupyter笔记本上运行dash,但应用程序没有启动。我得到SystemExit:1错误。请帮忙。我不是要求运行在笔记本,但只是要启动网络应用程序。如果我使用应用程序副本文件,它运行,但为什么我不能运行jupyter笔记本?在

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

我得到这个错误:

^{pr2}$

此烧瓶问题的%tb:

Flask issue


Tags: nameimportidnodeapp应用程序datahtml
1条回答
网友
1楼 · 发布于 2024-06-29 00:02:57

@i不在乎你要在jupyter笔记本中运行这段代码,只需更改几行。首先安装jupyter

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

那么jupyter plotly dash安装附带的dash有一个bug,需要降级到0.38.0。你可以用 [pip安装破折号==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
^{pr2}$

相关问题 更多 >