Hi!
I just started using Dash and am running into a problem that I feel has been solved but cannot find it. I am tying to create a simple table with in-row dropdowns, that when the dropdown is changed, the column data changes as well.
I have data for 17 units and a status for each one. Depending on the status, the hourly data report will change. (ie ‘Off’ will be all zeros, but ‘On’ will have non-zero data). The data I am reading in has both categories in it, so I wanted to have a row-dropdown to switch between what data is displayed on a Unit-by-unit basis.
I can create the table:
columns_burn = [
dict(id='Status',name='Status', presentation='dropdown'),
dict(id='Unit',name='Unit'),
#dict(id='RTODay',name='RTODay'),
dict(id='RTO',name='RTO'),
dict(id='Date',name='Date'),
dict(id='10',name='10',type='numeric'),
dict(id='11',name='11',type='numeric'),
dict(id='12',name='12',type='numeric'),
dict(id='13',name='13',type='numeric'),
dict(id='14',name='14',type='numeric'),
dict(id='15',name='15',type='numeric'),
dict(id='16',name='16',type='numeric'),
dict(id='17',name='17',type='numeric'),
dict(id='18',name='18',type='numeric'),
dict(id='19',name='19',type='numeric'),
dict(id='20',name='20',type='numeric'),
dict(id='21',name='21',type='numeric'),
dict(id='22',name='22',type='numeric'),
dict(id='23',name='23',type='numeric'),
dict(id='24',name='24',type='numeric'),
dict(id='1',name='1',type='numeric'),
dict(id='2',name='2',type='numeric'),
dict(id='3',name='3',type='numeric'),
dict(id='4',name='4',type='numeric'),
dict(id='5',name='5',type='numeric'),
dict(id='6',name='6',type='numeric'),
dict(id='7',name='7',type='numeric'),
dict(id='8',name='8',type='numeric'),
dict(id='9',name='9',type='numeric'),
]
dash_table.DataTable(
data=burn_list.to_dict('rows'),
id="burn_table",
columns = columns_burn,
style_cell={'textAlign': 'left'},
style_data_conditional=[
{
'if': {'row_index': 'odd'},
'backgroundColor': 'rgb(212,212,212)'
},
],
editable=True,
dropdown={
'id': 'Status_dropdown',
'Status':{
'options': [
{'label': i, 'value': i} for i in burn_data['Status'].unique()
] }}
)
and the dropdown menus show the correct options, but the callback I created doesnt seem to work
@app.callback(
Output('table-container','data'),
[Input('Status_dropdown','value'), Input('Unit','value')])
def update_table(Status_dropdown,Unit):
dff = burn_list[(burn_list['Status']== Status_dropdown) & (burn_list['Unit'] == Unit) ]
return dff.to_dict('rows')
My thought process was that each row has its own Status_dropdown, so the call back would update that row, but it only changes the dropdown menu.
Am I misunderstanding how the callback works? Is there a better way to create this table? One dropdown is not sufficient, which is why I went the per-row dropdown route.
Any help/feedback would be appreciated.