Streamlit Multipage app : How to keep running first page , if the user clicks the second page

Hi ,

I have a requirement where I need to bring some data from SQL Server and make available thru download button. I can able to achieve this requirement.

But the real problem is , when the user hits submit form button the program will do all the ELT work behind and make available download button , this might take more than 20 seconds.

In this 20 seconds mean while , user is going to another page to do some activity.

But when the user comes back to page1 , everything is like nothing is happened.

Could anyone have any suggestions how to achieve this. Much appreciated , Thank you!.


Here is my code

import streamlit as st
import pandas as pd
import time

st.title('Streamlit Multi Page app reruns')

colordata = {'Color':['White','Yellow','Black','Green','Purple']}
colordf = pd.DataFrame(colordata)

with st.form(key = 'colorchoice'):
    choice = st.selectbox('Select your color' , colordf)
    choicesubmitted = st.form_submit_button('Submit')

if choicesubmitted:
    f'You have seleted : {choice} color'
    for i in range(20,0,-1):

import streamlit as st
food = st.selectbox('Select your choice ', options=['Burger','Nuggets','Fries','Soda'])
f'You have selected {food}'

That’s a tricky one because if you change pages it will stop the execution.

Either you could:
a) Have a warning displayed on screen for the user not to click off the page while it is loading the data.
b) You could possibly achieve this using the subprocess module in Python.
You would need to send the command to another python/sql script using subprocess, then have that subprocess save the data somewhere, then when you click back to the page you will need to get streamlit to check if the file exists and if it does display the download button.

I think a) is much easier…

1 Like

Hi @LukeF , Thanks for letting me know about the sub process idea , it did not strike me. :slight_smile:

But yes, I agree first option is far better to let the user know.

1 Like