简体   繁体   English

在 Jupyter notebook 中运行 Dash 的问题

[英]Problems running Dash in Jupyter notebook

I just copy and paste the first batch of code from: https://dash.plot.ly/getting-started to my Jupyter notebook and this what I am getting:我只是将第一批代码从https://dash.plot.ly/getting-started复制并粘贴到我的 Jupyter 笔记本中,这就是我得到的:

Running on http://127.0.0.1:8050/ Debugger PIN: 124-434-522 Debugger PIN: 124-434-522 Debugger PIN: 124-434-522 Debugger PIN: 124-434-522 * Serving Flask app "__main__" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment.http://127.0.0.1:8050/上运行 调试器 PIN:124-434-522 调试器 PIN:124-434-522 调试器 PIN:124-434-522 调试器 PIN:124-434-522 * 服务 Flask 应用程序“__main__ “(延迟加载)*环境:生产警告:请勿在生产环境中使用开发服务器。 Use a production WSGI server instead.请改用生产 WSGI 服务器。 * Debug mode: on An exception has occurred, use %tb to see the full traceback. * 调试模式:在发生异常时,使用 %tb 查看完整的回溯。 SystemExit: 1系统出口:1

Any help will be more than appreciated.任何帮助将不胜感激。

(Updated comment) I have aslo tried google colab. (更新评论)我也尝试过谷歌 colab。 Unfortunately it doesn't work on it neither.不幸的是,它也不起作用。 this is what I am getting:这就是我得到的:

# -*- 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 (most recent call last) in () ----> 1 import dash 2 import dash_core_components as dcc 3 import dash_html_components as html 4 5 external_stylesheets = [' https://codepen.io/chriddyp/pen/bWLwgP.css '] () 中的 ModuleNotFoundError Traceback(最近一次调用)----> 1 import dash 2 import dash_core_components as dcc 3 import dash_html_components as html 4 5 external_stylesheets = [' https://codepen.io/chriddyp/pen/bWLwgP.css ']

ModuleNotFoundError: No module named 'dash' ModuleNotFoundError:没有名为“破折号”的模块

(Second update) I am running the same script in Atom. (第二次更新)我在 Atom 中运行相同的脚本。 Unfortunately it doesn't seen to be working:不幸的是,它似乎没有用: 在此处输入图像描述

I don't understand what I am doing wrong.我不明白我做错了什么。

This is the tutorial you are looking for https://plot.ly/python/ipython-notebook-tutorial/ .这是您正在寻找的教程https://plot.ly/python/ipython-notebook-tutorial/ As Alexander explained Dash is a web server.正如亚历山大解释的那样,Dash 是一个网络服务器。 If you are just learning python and want to plot stuff with Jupyter, running a webserver is not what you need.如果您只是在学习 Python 并想用 Jupyter 绘制内容,那么运行网络服务器并不是您所需要的。 Instead you have to install a plot library like plotly or my favorite matplotlib .相反,您必须安装像plotly或我最喜欢的matplotlib类的绘图库。 To install it, you would run ! pip install plotly要安装它,您将运行! pip install plotly ! pip install plotly from inside Jupyter.从 Jupyter 内部 plotly ! pip install plotly The tutorial will walk you through it.本教程将引导您完成它。

您的最后一张图片显示破折号运行良好转到终端中指示的 URL

You can not use debug=True with Jupyter Notebook.您不能将 debug=True 与 Jupyter Notebook 一起使用。 Change to False or else run the code from a code editor/IDE.更改为 False 或从代码编辑器/IDE 运行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM