Download-Button reloads app and results / output is gone

Hi there,
I use the new download button (way better then use some custom functions) and after using it to download e.g. data the app reloads and the output is gone. Is there any way to keep the generated output (not reload the app) and use the download button? Maybe some combination with forms?

Thx

Hi, @jpigla!

Could you please share the code snippet, and explain a little more in detail what you want to achieve?

In general, the logic of the download button is the same as for other widgets, that is, it leads to the app script rerun upon interaction.

Hi, sorry to let you wait.

df_query_result, gridOptions = clean_query_result(query_result, type_of_request)
with c2:
  AgGrid(df_query_result, gridOptions=gridOptions, enable_enterprise_modules=True)
  st.download_button(label='Tabelle herunterladen', mime='text/csv', file_name=f'Google_Trends_{date.today().strftime("%d-%m-%Y")}.csv', data=df_query_result.to_csv(index=False))

I am working on an app to get some data from Google Trends. After a button click some queries, data processing and output happens.

I want to give the ability to download some tables (DataFrames) during the exploration of the data. When the user clicks the download button (0.88.0 Release Notes, blue outlined button in screenshot) the app reruns and the generated data and output is gone… until the user clicks the “start” button (st.button) again (triggers query and output).
Maybe I can catch that rerun with auto set the button variable to True and cache the query function. :thinking:

I was wondering if there is some possibility to not rerun the app when the native download button is clicked. You pointed out that that behaviour is normal and expected like the other widgets…

As mentioned, to keep the output and give some download possibility I would stay with some download function and just style it like some button (smaller button in screenshot). I already got inspired by the great @Charly_Wargnier and his styling in https://share.streamlit.io/charlywargnier/bert-keyword-extractor/main/app.py :innocent:

Thanks for your support.