Hi , i would like to update a second DataTable based on the selection of the first datatable.
however as the layout has a html.Div with just the table id in it , as i create the tables using a function …
i seem to get an error … how should i work out that problem ? thank you
error:
layout code:
app.layout = html.Div([
html.Div([
html.Div([
dcc.Dropdown(id='dropdown',
options=[
{'label':'Daily','value':0}, # what value to pass ?
{'label':'Weekly','value':1}],
value = 0,
multi=False,
clearable=False),
],className='six columns'),
],className='row'),
html.Div([
html.Div([ html.Div(id='table1'),
],className='six columns'),
html.Div([html.Div(id='table2'),
],className='six columns'),
],className='row'),
])
callback code for dropdown selection: (works)
@app.callback(
Output("table1", "children"),
[Input("dropdown", "value")])
def update_table(selection):
if selection == 0:
rsc_daily = rsc_algo_test(sectors_df,daily)
rsc_daily_sector = pd.DataFrame(rsc_daily,columns=['Ticker','RSC','Price','Percent Change','Index'])
data=rsc_daily_sector.to_dict('rows')
columns=[{"name": i, "id": i, "deletable": False, "selectable": False} for i in rsc_daily_sector.columns]
return create_table(data,columns)
if selection == 1:
rsc_weekly = rsc_algo_test(sectors_df,weekly)
rsc_weekly_sector = pd.DataFrame(rsc_weekly,columns=['Ticker','RSC','Price','Percent Change','Index'])
data=rsc_weekly_sector.to_dict('rows')
columns=[{"name": i, "id": i, "deletable": False, "selectable": False} for i in rsc_weekly_sector.columns]
return create_table(data,columns)
callback code for second table: (doesent work) the None value comparison is just for initialization
@app.callback(
Output("table2", "children"),
[Input("table1", "selected_row"),
Input('dropdown','value')])
def update_table2(selection,chosen_row):
if chosen_row == None and selection == 0:
df_filtered_daily = rsc_algo_test(xlk_df,daily)
rsc_daily_xlk = pd.DataFrame(df_filtered_daily,columns=['Ticker','RSC','Price','Percent Change','Index'])
data=rsc_daily_xlk.to_dict('rows')
columns=[{"name": i, "id": i, "deletable": False, "selectable": False} for i in rsc_daily_xlk.columns]
return create_table(data,columns)