question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

st.download_button() should not rerun the entire page

See original GitHub issue

Hi 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:closed
  • Created 2 years ago
  • Reactions:14
  • Comments:28

github_iconTop GitHub Comments

35reactions
GitHunter0commented, Oct 13, 2021

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.

10reactions
legendof-seldacommented, Feb 8, 2022

any update on this issue?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found