Dash Table not showing at all in simple setup

Hi all,

I’m trying to get a dash table to provide an output with a simple code example below, when running this I don’t see an output dspite it being very similar to examples online.

Can anyone think of a reason as to why either this code is wrong or that the table is not showing up when running.

import pandas as pd
import dash

from dash import html
from dash import dash_table as dt

df = pd.DataFrame({"A": [1,2,3,4], "B": ['a', 'b', 'c', 'd']})

print(df)

app = dash.Dash()

app.layout = html.Div(dt.DataTable(id = 'table', data = df.to_dict('rows'), columns = df.columns))

if __name__ == '__main__':
    app.run_server()

Thanks!

Hi,

It seems to me that the problem is thw way you define the columns parameter. It should be a list of dictionaries with two required keys: id and name, not just df.colunms.

1 Like

As @jlfsjunior said you should assign DataTable column like below


app.layout = html.Div(dt.DataTable(id = 'table', data = df.to_dict('rows'), columns = [{"name": i, "id": i} for i in list(df.columns)]))