What is problem with my code

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

Hi @phoenix968 welcome to the forums.

You are using a different argument here, 19800 instead of 19700. It’s this data present in data source?

yes both of them are present there, i did that to know if new data is printed

Hi, just for troubleshooting sake. Increase the max_interval on the interval and see if the behaviour changes. If the data disappears later, you know what caused it…

In general the question would be, why to use an interval component when the max_interval is set to 1 :slight_smile:

i have used max_interval as -1 , for infinite recursion

Try returning just data instead of (data)

yes, already tried that, also used return [data] and return data and return (data)

I have uploaded the data file on github.

Yep, sorry small screen

its ohk, see if you can help, thanks for replying