Download button data parameter issues


Im trying to make a generate report button. Using st.download_button, I want so that on click I can run some expensive code that then generates a pdf file to download. As of now this “expensive pdf generation code” to produce data to download has to be done decoupled from the button.

Having it decoupled, it runs everytime the app is changed in terms of interaction (caching does not solve the issue) making user experience really slow.

Is there a way to make the data param wait? Or be able to pass a function that it will only run on click.

1 Like

Create a button to generate report, once the report is generated create a download button.

import streamlit as st

def generate_report(repfn):
    with open(repfn, 'w') as f:
    st.write('done report generation')

if st.button('generate report'):
    repfn = 'report.pdf'

    with open(repfn, "rb") as f:
            label="Download report",