App reloads when an expander with upload is expanded

Summary

I have a dash with dozens of expanders. Only a few expanders have an upload button in them. When those are expanded, the entire app reloads. The other expanders do not behave this way.

Steps to reproduce

Code snippet:

...
    with st.expander(exp_label, expanded=False):
                ...
            if data['upload_option'] == True :
                uploaded_file = st.file_uploader("Upload a new file:", type=['csv','xls','xlsx'], key=this_key+"_upload")
                if uploaded_file is not None:
                      [do stuff]

Only some expanders have this upload option, as the upload_option is only true for maybe 5-6 expanders.

The other expanders open and close with no problem.

The expanders with the upload option immediately invoke a reload of the whole app, almost as if st.rerun() was called (it is not, though).

Further, once the app reload is complete, I can open and close the expander as many times as I want and it does not invoke an app reload.

Expected behavior:

No reload when expander is expanded.

Debug info

This behavior is consistent between my local run (Win 11, run via streamlit run myfile.py) and the Streamlit cloud deployment.

Requirements file

streamlit
boto3
pandas
numpy
s3fs
nest_asyncio
slackclient
paramiko
sshtunnel
sqlalchemy
psycopg2-binary
fsspec
openpyxl

Bump. Anyone know? This is a significant interruption to my program flow.

Your code works as expected for me. There must be something else involved.

Any suggestions as to where to start? I’ve been poking at this for over a month with zero progress. My code just generates a series of expanders and this reload consistently happens only with the ones with upload buttons in them.

Just do what you did in the OP, but post code that we can run (without undefined names) and actually shows the issue.