问题 运行 Jupyter notebook 中的 Dash

Problems running Dash in Jupyter notebook

我只是复制并粘贴了第一批代码: https://dash.plot.ly/getting-started 到我的 Jupyter 笔记本,这是我得到的:

运行 在 http://127.0.0.1:8050/ 调试器 PIN:124-434-522 调试器 PIN:124-434-522 调试器 PIN:124-434-522 调试器 PIN:124-434-522 * Serving Flask 应用“__main__”(延迟加载) *环境:生产 警告:请勿在生产环境中使用开发服务器。 请改用生产 WSGI 服务器。 *调试模式:开 发生异常,使用 %tb 查看完整的回溯。 系统出口:1

我们将不胜感激任何帮助。

(更新评论) 我也试过 google colab。不幸的是,它也不起作用。这就是我得到的:

# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

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)

ModuleNotFoundError Traceback(最后一次调用) 在 () ----> 1 个导入破折号 2 将 dash_core_components 导入为 dcc 3 将 dash_html_components 导入为 html 4个 5 external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

ModuleNotFoundError: 没有名为 'dash'

的模块

(第二次更新) 我在 Atom 中 运行 相同的脚本。不幸的是,它似乎没有用:

我不明白我做错了什么。

这是您正在寻找的教程https://plot.ly/python/ipython-notebook-tutorial/。正如 Alexander 解释的那样,Dash 是一个网络服务器。如果您只是在学习 python 并且想用 Jupyter 绘制东西,那么 运行 网络服务器不是您所需要的。相反,您必须安装像 plotly 或我最喜欢的 matplotlib 这样的绘图库。要安装它,您需要从 Jupyter 内部 运行 ! pip install plotly。本教程将引导您完成它。

你的最后一张图片显示 dash 运行良好 转到终端

中指示的URL