Hey guys, so I have a dash-app that takes a bunch of inputs (at least 18), does some computation and appends the output to a CSV file. I’m using the submit button as a way of appending values to the csv file.
The problem is that every time I click on the submit button, my the page refreshes and as a result my Input fields are reset back to the default values. Is there a way to disable the page refresh or at the very least conserve the values on the Input fields?
Here is the code snippet responsible for appending the csv.
@app.callback(
Output(“nothing”, “data”),
[Input(“submit-button”, “n_clicks”)],
[State(“output_1”, “data”), State(“output_2”, “data”)],
)
def append_to_csv(n_clicks, output_1, output_2):
if n_clicks is None:
raise PreventUpdate
if (output_1 is None) or (output_2 is None):
raise PreventUpdate
else:
with open(“result.csv”, “a+”) as f:
f.write(f"{round(output_1,2)}, {round(output_2,2)}\n")
f.close()
return 1
Thanks!