python - 从 jupyter 笔记本运行破折号
问题描述
我正在尝试通过 jupyter notebook 运行 dash,但该应用程序未启动。我得到 SystemExit: 1 错误。请帮忙。我不是要求在笔记本中运行,而只是启动网络应用程序。如果我使用 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 对于这个烧瓶问题:
解决方案
@idontcare 您必须更改几行才能在 jupyter notebook 中运行此代码。首先安装 jupyter plotly dash with
[pip install jupyter-plotly-dash] 本次安装中的django需要通过安装[pip install -U django-plotly-dash==0.9.8]来设置。
那么jupyter-plotly-dash安装自带的dash有bug,需要降级到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
推荐阅读
- react-native - React Native 项目,有时使用 expo start 获得“连接 ECONNREFUSED 127.0.0.1:19001”
- javascript - 在函数中插入变量
- php - 如何使用 JavaScript 从服务器获取数据?(第一次将后端添加到 React 应用程序)
- excel - VBA根据单元格的定义名称设置单元格值
- javascript - 如何有效地将大文件加载到 IndexedDB 存储中?我的应用程序在超过 100,000 行时崩溃
- c# - MVVM wpf:如何连接我之前制作的 ObservableCollection 遇到 ViewModel
- algorithm - 我们真的需要在约翰逊算法中添加一个额外的节点吗?
- c++ - 这是一种什么样的说法?(第6章,使用C++的原理与实践)
- java - 在java中使用String builder反转数字
- solr - 无需搜索即可从 Solr 读取所有文档(仅在可能的情况下使用文档 ID)