St.file_uploader is returning to login page after file upload

Summary

st.file_uploader reruns the complete app and returns to main page after file uploads

Steps to reproduce

Code snippet:

Below func1 is called from another page having multiple tabs built using st.tabs

def func1():
    # st.text_input(label="Enter File Name")
    # st.text_input(label="Enter Text Column Name")
    with st.form('Form1'):
        uploaded_file = st.file_uploader("Please choose an Excel or CSV file for Labelling", type=['xlsx', 'csv'])
        submitted1 = st.form_submit_button('Submit 1')
        st.write(submitted1)
        if submitted1:
            if uploaded_file is not None:
                data = pd.read_excel(uploaded_file)
                st.write(data[3])```

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

**Expected behavior:**

Explain what you expect to happen when you run the code above.

Expected behavior is that file content is read by further code for processing of data
**Actual behavior:**
application is re running and returning to login page
Explain the undesired behavior or error you see when you run the code above.
If you're seeing an error message, share the full contents of the error message here.

### Debug info

- Streamlit version:1.25
- Python version:3.9

strangely when I added time.sleep(20) after st.file_uploader() functionality, file got stored and the remaining code lines worked fine

Hi,

It could be that the CSV file processing requires time for computation and that time.sleep(20) provides ample time for it to complete its processing before proceeding further in the workflow.

Perhaps you can figure out how to detect that the processing is completed and replace the time.sleep(20) with that. For example, generation of an output file, infer from anything that indicates that the calculation is completed, etc.

Hope this helps!

Thanks for replying. Actually, even with no computation in place, st.file_uploader is rerunning the complete app on file upload (and users gets back to login page), not sure why app needs to rerun completely with interactive widgets, I have tried using session_state as well but apparently only time.sleep(20) seems to let file gets uploaded properly and then if I have further interactive buttons after file uploading, then again app reruns based on button click. Is this unusual or its the way streamlit is designed ? Also, is there any proper work around for same ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.