jupyter notebook运行dash
时间: 2023-10-04 08:05:26 浏览: 178
要在Jupyter Notebook中运行Dash,需要执行以下步骤:
1. 确保已安装必要的库:dash和plotly
```python
!pip install dash
!pip install plotly
```
2. 在Jupyter Notebook中创建Dash应用程序
```python
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash(__name__)
app.layout = html.Div(
children=[
html.H1(children='Hello Dash'),
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)
```
3. 运行应用程序
```python
if __name__ == '__main__':
app.run_server(debug=True)
```
4. 在浏览器中打开应用程序
访问http://localhost:8050/,就可以在浏览器中看到运行的Dash应用程序。
阅读全文