Hi All,
I am trying to update part of rows of the same dash datatable. The example in the documentation shows how this can be done for columns (https://dash.plot.ly/datatable/editable), and I have figured out how this can be implemented for rows:
params_years = [1,2,3,4,5,6,7]
id_PL = ['Test']
params_PL = [1,2,3,4,5,6,7,8,9,10]
dash_table.DataTable(
id='adding-rows-table',
columns=(
[{'id': 'Test', 'name': 'Test', 'editable': False}] +
[{'id': p, 'name': p} for p in params_years]
),
data=[
dict({param: params_PL[i] for param in id_PL}) for i in range(0, len(params_PL))
],
editable=True,
row_deletable=True,
),
@app.callback(
Output('adding-rows-table', 'data'),
[Input('adding-rows-table', 'data_timestamp')],
[State('adding-rows-table', 'data')])
def update_rows(timestamp, rows):
sum_test = {k: int(rows[0].get(k, 0)) -
int(rows[1].get(k, 0)) +
int(rows[2].get(k, 0)) +
int(rows[3].get(k, 0)) +
int(rows[4].get(k, 0)) +
int(rows[5].get(k, 0))
for k in set(rows[0])}
rows[6] = sum_test
return rows
This works, but I don’t want params_PL to be integers. If I change params_PL to Strings, I get an error as Dash tries to add Strings together (which obviously fails). Does anyone know how I can make this work, while still using Strings in the left column, instead of Integers?
I think Dash rows are seen as dictionaries, but I just couldn’t get it to work. Many thanks for your help!