Summary
Right now we allow users to customise some data, and then hit a button to upload this data into an S3 bucket. Right now, we’re trying to figure out how to ensure this upload happens once, but right now it seems if a user double clicks this button then the streamlit code will run twice.
We’ve tried using st.session_state, global is_uploading
variables, and even a threading Lock
to try and ensure that this upload can only happen once. I’m sure there must be an easy solution I’ve overlooked, and so here I am, requesting some help in doing this!
Steps to reproduce
import time
import streamlit as st
def dummy_upload():
print("Uploading!")
time.sleep(1)
print("Upload done!")
if __name__ == "__main__":
if st.button("Upload now"):
dummy_upload()
Expected behavior:
A pattern whereby we only trigger the upload once (aka the dummy_upload is only called once, or theres a way to return out of it if something else is already executing).
Actual behavior:
A double click causes a double upload.
Debug info
- Streamlit version: 1.25.0
- Python version: 3.11.4
- pyenv
- OS version: Ubuntu
- Browser version: All
Requirements file
Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.
Links
- Link to your GitHub repo:
- Link to your deployed app:
Additional information
If needed, add any other context about the problem here.