簡體   English   中英

從Jupyter Notebook啟動Dash

[英]Launch Dash from Jupyter Notebook

有什么方法可以使用Jupyter筆記本中的以下代碼行啟動Dash dahsboard?

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

當我嘗試啟動此程序時,出現錯誤。

糾正它的唯一方法是將debug設置為false。 但是,當更改提供給圖表的數據時,儀表板不會自動更新。

編輯

我剛剛發現一個有價值的GitHub用戶發布了以下庫 這是到各個倉庫的直接鏈接。 請參閱他的文檔和示例以在jupyter中成功實現它。 它為我工作。

在安裝該庫之前,請不要低估此語句:“強烈建議使用virtualenv環境”!

原始帖子

我前一段時間有這個問題。 我不知道它現在是否已在本地修復。 我當時回想過的解決方法就是這個。 它直接來自克里斯本人,但是具有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)

因此,像這樣使用它可以為您切換回調函數嗎? 請顯示程序的一些邏輯。 也許我可以提供更多提示。 干杯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM