My question:
i have given my code below , my issue is with the dcc.Interval, as the data is printed first time but after the time interval i.e 2 second in this case, the table is empty.
My code:
from dash import Dash, dash_table, html, dcc, Input, Output
import pandas as pd
import dash_bootstrap_components as dbc
from dash.exceptions import PreventUpdate
excel_filename="13August2023.xlsx"
xls = pd.ExcelFile(excel_filename)
df = pd.read_excel(xls, sheet_name=str(19700))
app = Dash(__name__)
dashTable1 = dash_table.DataTable(
id='table',
data = df.to_dict('records'),
sort_action='native',
columns=[{'name': i, 'id': i} for i in df.columns],
)
app.layout = html.Div([
html.Div(
[
dcc.Interval(
id='my_interval',
# disabled=False,
interval=2*1000,
n_intervals=0,
max_intervals=-1,
),
html.Div([dashTable1],style={'display': 'inline-block',"margin-left": "15px"}),
]
)
])
@app.callback(
Output("table","data"),
Input("my_interval", "n_intervals"),
prevent_initial_call=True,
)
def update_table(interval):
dff= pd.read_excel(xls,sheet_name=str(19800))
data = dff.to_dict('records')
return (data)
if __name__ == '__main__':
app.run(debug=True)
my data: in the excel
CE | PE | percentage | Times | |||
---|---|---|---|---|---|---|
19700 | 3991650 | 149300 | 14:00 | 2573.58 | 26.74 | RES |
19700 | 24854150 | 7175500 | 13:45 | 246.38 | 3.46 | Sup |
19700 | 23978450 | 8372450 | 13:30 | 186.4 | 2.86 | Sup |
19700 | 24581350 | 9712200 | 13:15 | 153.1 | 2.53 | Sup |
19700 | 25697800 | 8208550 | 13:00 | 213.06 | 3.13 | Sup |
19700 | 25448650 | 8004350 | 12:45 | 217.94 | 3.18 | Sup |
19700 | 25570100 | 8019500 | 12:30 | 218.85 | 3.19 | Sup |
19700 | 23377350 | 8173300 | 12:15 | 186.02 | 2.86 | Sup |
19700 | 22809150 | 8081350 | 12:00 | 182.24 | 2.82 | Sup |
19700 | 24023450 | 6915550 | 11:45 | 247.38 | 3.47 | Sup |
19700 | 22708150 | 6557700 | 11:30 | 246.28 | 3.46 | Sup |
19700 | 21455350 | 6541550 | 11:15 | 227.99 | 3.28 | Sup |
19700 | 19891750 | 6250950 | 11:00 | 218.22 | 3.18 | Sup |
19700 | 21013900 | 5962600 | 10:45 | 252.43 | 3.52 | Sup |
19700 | 18940050 | 9940000 | 10:30 | 90.54 | 1.91 | Sup |
19700 | 17013650 | 13640000 | 10:15 | 24.73 | 1.25 | Sup |
19700 | 17107700 | 12542600 | 10:00 | 36.4 | 1.36 | Sup |
HTML output in start
HTML output after 2 second interval
Data File Link