I converted dataframe to a list of dictionary using df.to_dict(‘records’) and pass to datatable " data" using callback. But it gave me the following error,:
dash.exceptions.InvalidCallbackReturnValue: The callback for [<Output
Table1.data>, <Output
Table1.columns>]
returned a value having type list
which is not JSON serializable.
The value in question is either the only value returned,
or is in the top level of the returned list,
and has string representation
[{'Formulation': 'IG58', 'Component_1': 0.61, 'Source': 0.39, 'MFI2,16KG_FINAL': 6.5, 'IZOD23_FINAL': 29.27, 'FLEXURE_FINAL': 1147.22, 'Cost_Ton': 7622.80}]
In general, Dash properties can only be
dash components, strings, dictionaries, numbers, None,
or lists of those.
This is my code:
def get_table_data(pdf):
columns = [{“name”: i, “id”: i}for i in pdf.columns]
pdf = pdf.to_dict(‘records’)
return pdf, columns
@app.callback(
[Output(“Table1”, ‘data’), Output(“Table1”, ‘columns’)],
[Input(“Virgen-dropdown”, ‘value’),
Input(‘application-dropdown’, ‘value’)],
)
def update_table1(virgen_type, application):
if virgen_type == ‘All’:
Virgen = data
else:
Virgen = data.loc[data[‘Type’] == virgen_type, ]
df_1_virgen = one_components_formulation_calculator(Virgen, application, 0)
return get_table_data(df_1_virgen)
Any help would be much appreciated!!