st.download_button() should not rerun the entire page
See original GitHub issueHi folks,
Please, consider the MWE below:
import streamlit as st
import pandas as pd
with st.form(key='form1'):
user_input = st.text_input("Insert text")
submit = st.form_submit_button("Submit")
if submit:
st.warning("This part should not be lost after clicking the download button!")
st.write(user_input)
# Save dataframe as a .csv file
df = pd.DataFrame({"v1": [1,2,3]})
file_name = "df.csv"
file_path = f"./{file_name}"
#
df.to_csv(file_path)
# Create Download Button
file_bytes = open(file_path, 'rb')
st.download_button(label='Click to download',
data=file_bytes,
file_name=file_name,
key='download_df')
file_bytes.close()
Problem
st.download_button()
reruns the entire page, erasing everything that was opened after clicking “Submit”.
This behavior can be problematic, specially for applications that use st.form()
like this one.
Solution
Having an option in st.download_button()
to not rerun anything would be really great.
Thank you
Issue Analytics
- State:
- Created 2 years ago
- Reactions:14
- Comments:28
Top Results From Across the Web
How to stop reloading the page after selecting any widget with ...
Expectation: The text is not displayed, and the function only runs when clicking on the button. Main.py : import streamlit as st import...
Read more >How to prevent the reloading of the whole page when I let the ...
Hello everyone, I am building a page which let the user to run a query ... and where you don't want to re-run...
Read more >Streamlit Tricks — Application Reruns on Every Widget Click ...
would be, to swap your "Load Data" button widget to a checkbox widget using ... Also, let's not forget to initialise, st.session_state ....
Read more >How to add a download button in Streamlit - ProjectPro
Streamlit allows you to add interactivity directly into the app with the help of widgets. You can add a download button in Streamlit...
Read more >streamlit-ext - PyPI
... e.g. download button which won't cause rerun, set page width. ... import streamlit as st import streamlit_ext as ste from datetime import...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @vdonato !
Actually, I believe all suitable Streamlit components should have a
rerun parameter
with 3 options:rerun the entire page
(currently the default behavior)rerun everything below the current component but nothing above
rerun nothing
@kajarenc , I also don’t know how difficult it would be to implement it but in my view it would put Streamlit in another level of capabilities and fulfill the requirements of more intermediate/advanced developers.
Please let me know what you guys think about this and if I should open a separate issue for that.
Streamlit is awesome and with just a few improvements I believe it will be unstoppable.
any update on this issue?