Hi,
I am currently working on a POC where I am trying to create a button that, when clicked, will trigger some data processing and then automatically download a CSV file to the user’s Downloads. However, I am facing a challenge in making this functionality work as intended.
Here is a code snippet that illustrates my current approach:
download_report = st.sidebar.button("Download Diagnosis Report")
if download_report:
conversation = format_to_conversation(conv_data)
diagnosis_report = get_summary(conversation)
data = {'Conversation': [conversation],
'Diagnosis Report': [diagnosis_report]}
df = pd.DataFrame(data)
csv = df.to_csv().encode('utf-8')
datetime_stamp = f"{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}"
st.download_button(
label="Download data as CSV",
data=csv,
file_name=f'diagnosis_report_{datetime_stamp}.csv',
mime='text/csv',
)
As you can see, st.download_button
renders a new button for downloading the CSV file. However, my goal is to perform the download when the download_report
button is clicked, without the need for an additional button click.
I would greatly appreciate any guidance or suggestions on how to achieve this functionality