I am using the below code to update columns values and provision to add and delete rows. With row delete and add new callback values in columns are not updating. Can anyone help in this
from dash import Dash, dash_table, html
from dash.dependencies import Input, Output, State
app = Dash(__name__)
app.layout = html.Div([
dash_table.DataTable(
id='computed-table',
columns=[
{'name': 'Input Data', 'id': 'input-data'},
{'name': 'Input Squared', 'id': 'output-data'}
],
data=[{'input-data': i} for i in range(5)],
editable=True,
),
html.Button('Add Row', id='editing-rows-button', n_clicks=0)
])
# Call back to calculate the output data
@app.callback(
Output('computed-table', 'data'),
Input('computed-table', 'data_timestamp'),
State('computed-table', 'data'))
def update_columns(timestamp, rows):
for row in rows:
try:
row['output-data'] = float(row['input-data']) ** 2
except:
row['output-data'] = 'NA'
return rows
# Call back to add a new row
@app.callback(
Output('computed-table', 'data'),
Input('editing-rows-button', 'n_clicks'),
State('computed-table', 'data'),
State('computed-table', 'columns'))
def add_row(n_clicks, rows, columns):
if n_clicks > 0:
rows.append({c['id']: '' for c in columns})
return rows
if __name__ == '__main__':
app.run_server(debug=False, port = 8094)