Dash python plotly live update table

问题描述 投票:2回答:1

我是个新人,在情节上冲刺。我想绘制一个表,其值(行)将在一定的时间间隔后自动更新,但我不知道如何使用短划线表实验。该表已经保存为CSV文件,但我无法使其生效。

请帮忙!

有人可以指导我正确的方向我该怎么办你的帮助将受到高度赞赏。以下是代码。

                             import dash
        import pandas as pd
        from pandas import Series, DataFrame
        import dash
        from dash.dependencies import Input, Output, Event
        import dash_core_components as dcc
        import dash_html_components as html
        import dash_table_experiments as dtable
        app=dash.Dash()

        def TP_Sort():
            address = 'E:/Dats Science/POWER BI LAB DATA/PS CORE KPIS/Excel Sheets/Throughput.xlsx'
            TP = pd.read_excel(address)
            TP1=TP.head()
            Current_Interval.to_csv('TP1.csv', index=False)
            return
        app.layout = html.Div([
            html.H1('Data Throughput Dashboard-NOC NPM Core'),
            dcc.Interval(id='graph-update',interval=240000),
            dtable.DataTable(id='my-table',
                             rows=[{}],
                             row_selectable=False,
                             filterable=True,
                             sortable=False,
                             editable=False)
        ])
        @app.callback(
                     dash.dependencies.Output('my-table','row_update'),
                     events=[dash.dependencies.Event('graph-update', 'interval')])
        def update_table(maxrows=4):
            TP_Sort()
            TP_Table1='C:/Users/muzamal.pervez/Desktop/Python Scripts/TP1.csv'
            TP_Table2=pd.read_csv(TP_Table1)
            return TP_Table2.to_dict('records')    


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

我正在尝试上述方法。请纠正我错误的地方,因为输出是错误加载依赖项。

BR
Rana 
python-3.x plotly-dash
1个回答
3
投票

你的回调是错误的。

它应该是:

@app.callback(Output('my-table', 'rows'), [Input('graph-update', 'n_intervals')])
def update_table(n, maxrows=4):
    # We're now in interval *n*
    # Your code
    return TP_Table2.to_dict('records')
© www.soinside.com 2019 - 2024. All rights reserved.