Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Data table column headers are numbers not the column names

I’ve got a table populating from a mysql db but the column headers are coming out as numbers 0,1,2,3, etc instead of the names they have. Any ideas on how to fix this anyone?

app = dash.Dash()
app.layout = html.Div([
    dt.DataTable(
        rows=[{}],
        id='table'
    ),
    dcc.Interval(id= 'graph-update',interval=10*1000),
    ])


@app.callback(
    Output('table', 'rows'),
    events=[Event('graph-update', 'interval')]
    )
def gen_table():
    conn = pymysql.connect()
    query = ""
    c = conn.cursor()
    c.execute(query)
    dh = pd.DataFrame([[ij for ij in i]for i in c])
    return dh.to_dict('records')


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

you should define them in the layout.
columns=…

Oh sorry I forgot to add in the columns=[] bit but how do I get that fed from the callback?

do your columns change depending on the callback?

Yeah I’ve another graph and depending on the click Data from that the query changes and returns different columns

hmm… maybe you could have an empty div (container) and return the whole dt.Datatable in the callback?
Ive never done this but worth a shot.

yeah I’ve tried that but I’ll give it another shot and hope it was just a small mistake last time