Calling Table inside function


#1

def make_dash_table(df):
return html.Div([html.H4(‘DataTable’),
dt.DataTable(
rows=df.to_dict(‘records’),
),])

It says : Type Error Object of type ‘DataFrame’ is not JSON serializable.

How can I create table this way inside function


#2

If I am not mistaken, which I am sometimes :slightly_smiling_face:, this should help:
You need to return something like;

return df.to_json(orient='split')

, instead of your df.to_dict.


#3

Same ERROR!
Type Error Object of type ‘DataFrame’ is not JSON serializable.


#4

How are you calling make_dash_table?