Dash python plotly live update table

Muzamal Rana picture Muzamal Rana · Jul 30, 2018 · Viewed 7.8k times · Source

I am new to plotly dash. I want to draw a table whose values (Rows) will automatically be updated after certain interval of time but i do not know how to use dash table experiments. The table is already saved as CSV file but i am somehow unable make it live.

Please help!

Can some one guide me in the right direction what should i do Your help will be highly appreciated. Following is the code.

import dash
import pandas as pd
from pandas import Series, DataFrame
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)

I am trying the above approach. Please correct me where i am wrong as the output is error loading dependencies.

BR Rana

Answer

Nils picture Nils · Aug 1, 2018

Your callback is wrong.

It should be:

@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')