Currently, I have a dashboard that allows users to export queried data in xlsx/csv format but the file generated is stuck with data that is first queried by the first user. If another user queries his/her own data and tries to export, he/she would open the downloaded file and see the data queried by the first user in another instance.
I believe this is due the global variable “queried_df” shown below in my code snippet. Is there a better way to share/send data from the callback to the server route export?
Any other suggestions are appreciated, thank you!
@app.callback( Output('tables', 'children'), [Input("bom_1", "value"), Input("bom_2", "value"), Input("org_1", "value"), Input("org_2", "value"), Input("level", "value"), Input('button', 'n_clicks')] ) def update_tables(bom_1, bom_2, org_1, org_2, level, n_clicks): global queried_df if n_clicks == 0: return dash.no_update queried_df = bc.compare(bom_1, org_1, bom_2, org_2, level) # perform other actions return table @app.server.route('/export/') def download_excel(): strIO = io.BytesIO() writer = pd.ExcelWriter(strIO, engine="xlsxwriter") left = queried_df left.to_excel(writer, sheet_name='Sheet1', startrow=1) excel_data = strIO.getvalue() strIO.seek(0) return send_file(strIO, attachment_filename='test.xlsx', as_attachment=True)