New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
file_uploader does not repopulate the UploadedFile stream when the app is rerun #2213
Comments
|
Exalate commented: FrankKr commented: Update: in your example: original: |
|
Exalate commented: vik-s commented: Update: So, something like: Original: Thanks for your workaround. When I tried it, I get: Is there something specific I must do to access that method? edit: typo |
|
you're right, I posted a little too fast and my suggestion contained an error. I corrected it for future reads. Good luck! |
|
Thanks for finding this much better workaround, and for finiding the real underlying reason of the bug. |
Summary
I use
st.file_uploaderto allow the user to submit their own data. Then I do an action based on this data and other user-provided parameters (coming from anst.sliderfor instance). Re-running the app produces an error. This includes when the parameters are changed (for example by moving thest.slider). After investigating, I discovered that it is because, after the first reading of the UploadedFile output byst.file_uploader, the UploadedFile stays empty. It is not re-populated by the uploaded file in spite of the app re-running.Steps to reproduce
streamlit run my_app.py
5. Move the slider, here is the bug, you should see that:
6. At this point, re-uploading works, but the user shouldn't have to re-upload the file after each slider change or each plain re-run. Especially since, as we see in the screenshot above, the widget still displays the informations of the uploaded file. Here is how it looks after re-uploading:Expected behavior:
We shouldn't ever get to the second screenshot. We should pass from the first to the third simply by moving the slider and without re-uploading the file every time.
Actual behavior:
As explained above, after the first run the stream is empty and not reset when the app is re-run. This is not specific to the JSON format, although the error message displayed above is. I have run the same test with a CSV file and
pandas.read_csv. The underlying cause is the same: an empty stream.Note that I have also tried to make an auxiliary function that encapsulates the
dico = json.load(uploaded_file)part and which is decorated byst.cache. It still doesn't work.Is this a regression?
I don't know, it's the first time I use
st.file_uploader.Debug info
I have two different settings.
An AWS distant machine (I forward the port to my local machine):
My local machine:
Additional information
Side note on the documentation of
st.file_uploader: at the some point it says to useStringIO(uploaded_file.decode("utf-8"))but this doesn't work and raisesAttributeError: 'UploadedFile' object has no attribute 'decode'. UsingStringIO(uploaded_file.read().decode("utf-8"))does work, though.The text was updated successfully, but these errors were encountered: