I’m trying to fill and update a table using a callback, but I only get an empty table with the columns names. To check the interactivity, I added a html.Div that follows the same structure and prints the input to both callbacks. I also added a print() statement into the dataTable callback to be sure it was actually called, and it works well, however, no numbers appear on the table. I assume I have a problem with the syntax, but I cannot find out how to fix it.
This is the part of the code that deals with the table:
data = pd.DataFrame()
html.Div([
html.Div(id='my-div'),
dash_table.DataTable(id='table_upper',columns=[{"name": i, "id": i} for i in data.cols])
])
@app.callback(
dash.dependencies.Output('table_upper', "data"),
[dash.dependencies.Input('subject-dropdown', 'value')])
def update_table(subject):
data = ML_subject[subject]['upper'].iloc[:2]
print(data)
return data.to_dict('rows')
@app.callback(
Output(component_id='my-div', component_property='children'),
[Input('subject-dropdown', 'value')])
def update_output_div(subject):
return 'You\'ve entered "{}"'.format(subject)