I implemented a live-update feature to the add column function based on the documentation on editable DataTable https://dash.plotly.com/datatable/editable such that a new column is added to the datatable when the CSV file is updated. I've got the callback working and I need to save the state of the datatable in a dcc.store, which was kindly recommended to me, so that I store the current number of columns, and add only the newly updated columns based on the new CSV data. I need to do this because users input data the table, and if I live update the whole table the data is lost. I do not know if I can access the user input data in dcc.store, so instead I only wish to add on new columns to the datatable thereby preserving using input.
My question: is there a way I can assess the current number of columns in an existing data table?
app.layout = html.Div([
dcc.Store(id='mystore'),
html.Div([dash_table.DataTable(
id='editing-columns',
columns=[{
'name': 'Parameter',
'id': 'column1',
'deletable': True,
'renamable': True
}],
},
data=[
{'column1': j}
for j in table_contents
],
]),
])
@app.callback(Output('mystore', 'data'),
Input('graph-update', 'n_intervals'),
State('editing-columns', 'data'))
def serve_layout(n,data):
print(data)
data2 = json.dumps(data)
return data2
Output