Automatically overwriting .csv file from updated data frame?

I was wondering if there is any way to automatically overwrite a .csv file. Basically, I would have a user inputs something in the app, then my function would update the data table with that input and also let the user know that their input has been successfully received. However, I also want to update the base .csv that the dataframe reads on - so that would be a loop: we have a .csv file, dataframe reads it, the user updates it in the app, the dataframe gets updated, and the .csv file would be updated also. I have this so far:

def submit_reviews(n_clicks, claims_list, verdict, category, review):
    if n_clicks == 0:
        return (dash.no_update, dash.no_update, dash.no_update, dash.no_update, dash.no_update)
    
    if n_clicks and claims_list and verdict and category and review:
        new_df["Reviewed_Indicator"] = new_df.apply(lambda row: verdict
                                                                  if row["Claim_Number"] in claims_list else row["Reviewed_Indicator"], axis = 1)
        new_df["Reviewed_Category"] = new_df.apply(lambda row: category
                                                                  if row["Claim_Number"] in claims_list else row["Reviewed_Category"], axis = 1)
        new_df["Reviewed_Reason"] = new_df.apply(lambda row: review 
                                                                  if row["Claim_Number"] in claims_list else row["Reviewed_Reason"], axis = 1)

        dcc.send_data_frame(new_df.to_csv, "results_test.csv", index=False)

        
        return ([], True, "success", "Thank you. Your review has been submitted.", 1)

    else:
        return (dash.no_update, True, 
                "danger", "Error submitting review. Please review your submission.", dash.no_update)

However, the send data frame action does not seem to run anyhow.

You need to return the output of dcc.send_data_frame as the "data" property of a dcc.Download component.

See documentation: Download | Dash for Python Documentation | Plotly

I guess you need to refresh your components after the users have submitted the data successfully, and re-read the data. Plus, I suggest you use a database like SQLite to avoid transaction problems.

After reading the documentation more carefully, I think dcc.send_data_frame does not suit what I want. to_csv is probably what I need since I just need to output the .csv file on the server.

However, even after trying that and refreshing it, the file still does not show up in the files section - not even after I stopped the job and committed the result. Perhaps is it something else I did wrong?

Strange. I did refresh it, even stopped and committed the result, but no luck. I am using Domino to host this app.

What about locally? Does it work?

Also, I may have misunderstood your problem. As I understand, you want your app to write on disk the CSV file automatically, without prompting any download, right?

Yes, I would like to write a csv file on the server automatically without prompting any downloading action. An interesting thing I found is that, I put 2 print statements, one before and one after the csv exporting statement. Both print statements are good, they print out what I want. I suppose this is a problem with the platform hosting my app (Domino) so I will see what to do with it. Thanks everyone!

Yes, that’s why I asked you if your code works locally. There may be some permission errors happening on the server.