Invalid argument `columns[1].name` passed into DataTable

dash_table.DataTable(
style_data={‘whiteSpace’: ‘normal’},
css=[{
‘selector’: ‘.dash-cell div.dash-cell-value’,
‘rule’: ‘display: inline; white-space: inherit; overflow: inherit; text-overflow: inherit;’
}],
data=bed.to_dict(‘records’),
columns=[{‘id’: str(c), ‘name’: c} for c in bed.columns],
# fixed_rows={ ‘headers’: True, ‘data’: 0 },
style_cell={‘width’: ‘150px’,‘textAlign’: ‘left’},
style_cell_conditional=[
{‘if’: {‘column_id’: ‘Region’},‘textAlign’: ‘left’}
],
style_data_conditional=[
{‘if’: {‘row_index’: ‘odd’},‘backgroundColor’: ‘rgb(248, 248, 248)’}
],
style_header={
‘backgroundColor’: ‘rgb(0,0,0)’, #‘rgb(230, 230, 230)’,
‘fontWeight’: ‘bold’,‘color’: ‘yellow’,‘fontSize’: 20
},
style_table={
‘maxHeight’: ‘100’,
# ‘overflowY’: ‘scroll’
‘border’: ‘thin lightgrey solid’
},
),

1 Like

I had just ran into the same error, and for me the issue was that the column names were integers and not strings. so then the dictionary created in

columns=[{'name': i, 'id': i,} for i in df.columns]

gets an error because it will read {‘name’: 2013, ‘id’: ‘2013’} and not {‘name’: ‘2013’, ‘id’: ‘2013’}.

3 Likes

So how do you turn that key ‘name’'s value to a string?

With something like this:

columns=[{'name': str(i), 'id': str(i)} for i in df.columns]
3 Likes