How to Append Dataframes to a Master Dataframe with user interactions

Hi All,

I’m working on a Dash app that utilizies various data inputs to update a model. When I have a model that I like, I want to click a button to essentially capture a snapshot of the model, and append this to a master dataframe.

This master will allow me to call the different iterations using a unique index column that is inserted each time a new dataframe is created, and the ‘save button’ is clicked.

I believe the way to do this is

  1. Save the data from the model as a data object, and append that to the master list:
    dataframe_list is the master dataframe, i want to append models to
    save_model is the ‘save button’
    memory-output is the unique dataframe model that has been created with user input, that I want to save the values of
    and drug_str is the unique column that will serve as an identifier for future data visualization with the individual models

########################################
#Save DataFrame
########################################
@app.callback(
Output(‘dataframe_list’, ‘data’),
[Input(‘save_model’, ‘n_clicks’),
Input(‘memory-output’, ‘data’),
Input(“drug_str”, “value”)],
[State(‘dataframe_list’, ‘data’)])
def save_dataframe(n_clicks, data, drug_str):
df = pd.DataFrame(data)

if n_clicks >1:
    for index, row in df.iterrows():
        df.loc[1:, '{}'] = drug_str
    df.append(data, ignore_index=True)
return df.to_dict()