如何使用python库中的DASH更新仪表板

时间:2019-11-07 15:54:28

标签: python dashboard hyphen

我正在使用下面Dash库中的破折号示例。链接为https://dash-gallery.plotly.host/dash-financial-report/

如何修改此应用程序文件以自动更新在一个回调页面中构建的破折号表,该破折表是从sqlAlchemy数据库中读取的(不是原始文件中的CSV文件)? 假设我每5分钟更新一次表格,并且信息中心会自动重新创建表格。 此外,我还需要每5分钟回调一次查询数据库。

我是否可以创建一个“更新”按钮以至少刷新仪表板?

我们如何使用Dash做到这一点?

非常感谢

致谢。

    import dash
    import dash_core_components as dcc
    import dash_html_components as html
    from dash.dependencies import Input, Output
    from pages import (
        overview,
        pricePerformance,
        portfolioManagement,
        feesMins,
        distributions,
        newsReviews,
    )

    app = dash.Dash(
        __name__, meta_tags=[{"name": "viewport", "content": "width=device-width"}]
    )
    server = app.server

    # Describe the layout/ UI of the app
    app.layout = html.Div(
        [dcc.Location(id="url", refresh=False), html.Div(id="page-content")]
    )

    # Update page
    @app.callback(Output("page-content", "children"), [Input("url", "pathname")])
    def display_page(pathname):
        if pathname == "/dash-financial-report/price-performance":
            return pricePerformance.create_layout(app)
        elif pathname == "/dash-financial-report/portfolio-management":
            return portfolioManagement.create_layout(app)
        elif pathname == "/dash-financial-report/fees":
            return feesMins.create_layout(app)
        elif pathname == "/dash-financial-report/distributions":
            return distributions.create_layout(app)
        elif pathname == "/dash-financial-report/news-and-reviews":
            return newsReviews.create_layout(app)
        elif pathname == "/dash-financial-report/full-view":
            return (
                overview.create_layout(app),
                pricePerformance.create_layout(app),
                portfolioManagement.create_layout(app),
                feesMins.create_layout(app),
                distributions.create_layout(app),
                newsReviews.create_layout(app),
            )
        else:
            return overview.create_layout(app)


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

一页是:https://github.com/plotly/dash-sample-apps/blob/master/apps/dash-financial-report/pages/overview.py

0 个答案:

没有答案