Pass a Pandas DataFrame to a Bootstrap Table from a callback?

Has anyone been able to successfully pass a df to a dbc.Table.from_dataframe() using a callback? I think it would be relatively simple but haven’t been successful so far.

Any help would be appreciated.


Hi @cgeorge

I never did it, but reading the documentation seams to be very simple, just pass the DataFrame as ‘children’ to the table, showing table in the layout as:

dbc.Table.from_dataframe(df, striped=True, bordered=True, hover=True)

If I understand correctly, the first argument is the ‘children’ then replace df for your DataFrame.

If do not work, show your code and the error you are facing.

1 Like

I think the easiest thing to do is to actually call dbc.Table.from_dataframe inside the callback and pass the output to a wrapper element. Something like the below.

app.layout = html.Div(id="table-container")

@app.callback(Output("table-container", "children"), [Input(..., ...)]))
def make_table(...):
    df = make_df_from_inputs(...)
    return dbc.Table.from_dataframe(df, ...)

The Table component itself isn’t able to understand a dataframe, the .from_dataframe method is really just a convenience function that converts a dataframe to Dash html components, but you can’t directly pass a dataframe to the table from a callback.


@tcbegley Great explanation, got it working now. Thanks!

1 Like

Hey Tom,

Thanks for the explanation !!!

It’s a very easy way to assign a DataFrame to a Table :smiley:

1 Like