Hello,
I am trying to get the value from a callback function. This is the code :
layout = html.Div([
html.Div(id='table2'),
])
@callback(
Output('table2', 'children'),
Input('table', 'active_cell')
)
def filter_data(active_cell):
if active_cell:
selected_row = df.iloc[active_cell['row']]
selected_1 = selected_row['1']
selected_2 = selected_row['2']
print(selected_2)
if selected_1 != "a" and selected_2 != "b":
filtered_df = filtered_df[(filtered_df['1'] == selected_1) & (filtered_df['2'] == selected_2)]
table2 = dash_table.DataTable(id='table2',columns=[{'name': col, 'id': col} for col in filtered_df.columns],data=filtered_df.to_dict('records'))
return table2
#else:
#return html.Div()
else:
return html.Div()
here you can see i have created a dash table within the function and it is returning the Dash table after some pre processing steps.
The code is working fine for me when i run the app.py file for the first time and I am getting the desired output.
But, as you can see the in @callback input, I have set the input to Input('table', 'active_cell')
.
when I try to select the parent table row again in the same session, i am unable to get the updated child table.
Í tried to print the table2 value before reurning it…
here, is where the funny thing happens, I am getting the desired result in the terminal but, not in the web Layout.
The layout value stays the same filtered table from the initial selection.
Hope my question makes sense.
Basically i need to understand why the return statement is not working as intended.
P.S the input 'table ’ here is a dash table as well.