Dash table callback not updating

i have a dataTable which i want to update when i input values from dropdown and radiobuttons but i couldn’t . For the sake of this problem i’m not using input from the radiobuttons. below is my code

fno_df = pd.DataFrame({"Symbol": [],'token':[], 'daily_chg': [], 'rolweek_chg': [], 'lastweek_chg': [], 'rolmonth_chg': [], 'lastmonth_chg': [], 'rolquart_chg': [], 'lastquart_chg':[]})
 app = JupyterDash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
dropdown_list = ['Sectoral Indices', 'F&O Stocks', 'Nifty 50', 'Bank Nifty', 'NIFTY NEXT 50', 'NIFTY 200', 'NIFTY 500', 
                 'NIFTY AUTO', 'NIFTY FIN SERVICE', 'NIFTY FINSRV25 50', 'NIFTY FMCG', 'NIFTY IT', 
                 'NIFTY MEDIA', 'NIFTY METAL', 'NIFTY PHARMA', 'NIFTY PSU BANK', 'NIFTY PVT BANK', 'NIFTY REALTY', 
                 'NIFTY HEALTHCARE', 'NIFTY CONSR DURBL', 'NIFTY OIL AND GAS', 'NIFTY ENERGY', 'NIFTY INFRA']
time_frames = ["Daily", 'Rolling Week', 'Last Week',"Rolling Month",'Last Month', 'Rolling Quarter', 'Last Quarter']
advances = "x"
decline = "y"
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')

adv_dec_card = dbc.Card(dbc.CardBody([
html.H4("Advances / Decline", className = "card-title"),
html.P(
f"{advances} / {decline}", className = "card-text"
, id='card_text')
]
),style = {"width": "18rem", "text-align":"center"}
)

img_url = 'https://www.tetonpinesfinancial.com/wp-content/uploads/2016/01/Bulls-vs.-Bears.jpg'

#def layout():

app.layout = dbc.Container([
    dbc.Row([
        dbc.Col([ html.H1(children="Dashboard", className="text-center  text-info"), html.Hr()])
    ]),
    dbc.Row([
        dbc.Col([
            dcc.Dropdown(id='drpdown', options = dropdown_list, value='Nifty 50'),
            html.Br(),
            dcc.RadioItems(options=time_frames, value="Daily", labelStyle={'display': 'block'}, style = {'padding':10, 'fontSize':18}, id='rad_itm'),
            html.Br(),
            adv_dec_card
        ], width = {'size':4} ),
        dbc.Col([
            dash_table.DataTable(data=df.to_dict('records'), columns=[{'name':i} for i in df.columns], id='datatable' ) 
        ], width = {'size':8})
    ])
            
    ], fluid=True)

@app.callback(
    Output(component_id='datatable', component_property='data'),
    Output(component_id='datatable', component_property='columns'),
    Input(component_id='drpdown', component_property='value'),
    Input(component_id='rad_itm', component_property='value')
)
def update_table(drp, time_frm):
    token = instrument_df.loc[instrument_df['tradingsymbol'] == drp, 'instrument_token'].iloc[0]
    records = kite.historical_data(token, from_date = from_date, to_date = to_date, interval = 'day')
    records = pd.DataFrame(records)[['date', 'close']]
    records['Date'] = [d.date() for d in records['date']]
    change = pd.DataFrame({'returns':[]})
    col = [{"name": i, "id": i} for i in fno_df.columns]
    df = fno_df.to_dict('records')
    return df, col



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

Can you check your dataframe? It looks like your df and instrument_df is not the same.
And I didn’t see any mention about instrument_df in your code but callback.

1 Like