Append Row to Datatable

Hi Adam! Thank you for the link; I will try out this implementation and see if it suits my needs better, but I was actually able to find another way to append a row to a datatable. Below is an example for anyone who may find it helpful.

# Layout
columns = [
     {'id': 'value1', 'name': 'Column 1'},
     {'id': 'value2', 'name': 'Column 2'},
     {'id': 'value3', 'name': 'Column 3'},
],
data=[]


#Callback
@app.callback(
    Output('table', 'data'),
    [Input('add-row-button', 'n_clicks')],
    [State('table', 'data'),
    State('table', 'columns')]
)
def add_row(n_clicks, rows, columns):
     data = {'value1':my_var1, 'value2':my_var2, 'value3':my_var3}
     rows.append({c['id'] = data[c['id']] for c in columns})

     # Note: You can also create a pandas dataframe from the datatable with this:
     df = pd.DataFrame(rows, columns=[c['id'] for c in columns])

     return rows

@adamschroeder It’s great to see you on the forum; your videos have been extremely helpful! I’ll definitely be reading your book soon too.

And I hate to bother you with this here, but just off the top of your head, would you happen to know of a way to download a Dash page as an html? No worries if not. I asked this question a little while ago but am still unsure.

Thank you again for all of your help with Plotly Dash!

1 Like