从Jupyter Notebook启动Dash [英] Launch Dash from Jupyter Notebook

查看:1020
本文介绍了从Jupyter Notebook启动Dash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Jupyter笔记本中的以下代码行启动Dash dahsboard?

Is there a way I can launch a Dash dahsboard using the below line of code in Jupyter notebook?

# if __name__ == '__main__':
#     app.run_server(debug=True)

当我尝试启动它时,我得到一个错误.

When I try to launch this I get an error.

更正此错误的唯一方法是将debug设置为false.但是,当更改提供给图表的数据时,仪表板不会自动更新.

The only way to correct it is to set debug to false. But then the Dashboard does not update automatically when the data feeding the charts is altered.

推荐答案

编辑

我刚刚发现一个有价值的GitHub用户发布了后续库.这是到各个 repo 的直接链接.请参阅他的文档和示例,以在jupyter中成功实现它.它对我有用.

I just found out that a valuable GitHub user published the following library. This is the direct link to the respective repo. See his documentation and examples to implement it successfully within jupyter. It worked for me.

在安装库之前,请不要低估此语句:强烈建议使用virtualenv环境"!

DON'T understimate this statement before installing the library: "Use of a virtualenv environment is strongly recommended"!

原始帖子

我前段时间遇到了这个问题.我不知道它现在是否已在本地修复.我当时回想过的解决方法是此方法.它直接来自克里斯本人,但具有debug = False:

I had this problem myself some time ago. I don't know if it is natively fixed by now. The workaround snipped I used back that time is this one. It is directly from Chris himself, but has stil debug = False:

from IPython import display
def show_app(app,  # type: dash.Dash
             port=9999,
             width=700,
             height=350,
             offline=True,
             style=True,
             **dash_flask_kwargs):
    """
    Run the application inside a Jupyter notebook and show an iframe with it
    :param app:
    :param port:
    :param width:
    :param height:
    :param offline:
    :return:
    """
    url = 'http://localhost:%d' % port
    iframe = '<iframe src="{url}" width={width} height={height}></iframe>'.format(url=url,
                                                                                  width=width,
                                                                                  height=height)
    display.display_html(iframe, raw=True)
    if offline:
        app.css.config.serve_locally = True
        app.scripts.config.serve_locally = True
    if style:
        external_css = ["https://fonts.googleapis.com/css?family=Raleway:400,300,600",
                        "https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css",
                        "http://getbootstrap.com/dist/css/bootstrap.min.css", ]

        for css in external_css:
            app.css.append_css({"external_url": css})

        external_js = ["https://code.jquery.com/jquery-3.2.1.min.js",
                       "https://cdn.rawgit.com/plotly/dash-app-stylesheets/a3401de132a6d0b652ba11548736b1d1e80aa10d/dash-goldman-sachs-report-js.js",
                       "http://getbootstrap.com/dist/js/bootstrap.min.js"]

        for js in external_js:
            app.scripts.append_script({"external_url": js})

    return app.run_server(debug=False,  # needs to be false in Jupyter
                          port=port,
                          **dash_flask_kwargs)

那么像这样使用它可以为您切换回调函数吗?请显示程序的一些逻辑.也许我可以为您提供更多提示.干杯.

So using it like this is switching of callback functions for you? Please show some of the logic of your program. Maybe I can help with further tips. Cheers.

这篇关于从Jupyter Notebook启动Dash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆