import streamlit as st
with st.form("form"):
submitted = st.form_submit_button("submit")
if submitted:
st.write("this line should not disappear after click download")
st.download_button(
label="download",
data="file",
file_name='ok.txt',
)
My real code will do some calculation and show the result (chart and tables) after click form_submit_button.
But if I click the download_button, the calculation result will disappear.
How to resolve this?
And a suggestion, data parameter could be a function name, which runs on click
The answer to your questions is that everything causes the Streamlit page to re-load, that’s how the execution model works:
If you want to maintain a specific result between runs, you can accomplish that by using st.experimental_memo or st.experimental_singleton (or the legacy version st.cache, but I wouldn’t recommend that for new code).
Hi @randyzwitch , I know I can save result using cache or state between rerun/sessions.
But my main question is why download_button reload the page, it shouldn’t.
any time something must be updated on the screen, Streamlit reruns your entire Python script from top to bottom
Download button is not a kind of control flow or will update something on the screen but just an output. For example, a chart created by st.altair_chart will provide a download button on the chart element and click it won’t reload the page.
Is there any way to disable the reload feature of download_button ?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.