Skip to content
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 with beta_expander #3557

Closed
schaumb opened this issue Jul 15, 2021 · 4 comments · Fixed by #3660
Closed

file_uploader with beta_expander #3557

schaumb opened this issue Jul 15, 2021 · 4 comments · Fixed by #3660
Assignees
Labels
priority:P2 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working

Comments

@schaumb
Copy link
Contributor

schaumb commented Jul 15, 2021

Summary

In a beta_expander a file_uploader widget's uploaded file information is disappearing from front-end after closed and re-expanded the expander

Steps to reproduce

Code snippet:

import streamlit as st

with st.beta_expander('Config file', expanded=True):
  if st.file_uploader(''):
    print('file is uploaded')
  1. Upload a file
  2. Close the beta_expander
  3. Open the beta_expander

Expected behavior:

The uploaded file information (file name, file size, and ability to remove attaching) is there

image

Actual behavior:

The uploaded file information is missing

image

Is this a regression?

probably no, an older version (0.76.0) streamlit neither works

Debug info

  • Streamlit version: Streamlit, version 0.84.1
  • Python version: Python 3.6.9
  • No venv.
  • OS version: Linux Mint 19.2 Tina
  • Browser version: Mozilla Firefox 89.0.2 (64-bit)
@schaumb schaumb added type:bug Something isn't working status:needs-triage Has not been triaged by the Streamlit team labels Jul 15, 2021
@vdonato vdonato self-assigned this Jul 20, 2021
@vdonato vdonato removed the status:needs-triage Has not been triaged by the Streamlit team label Jul 20, 2021
@vdonato
Copy link
Collaborator

vdonato commented Jul 20, 2021

Thanks for reporting this @schaumb! It turns out we're actually discussing how this should work from a product standpoint as a related bug (#3512) brought the behavior of widgets that are removed and redisplayed to our attention.

Exactly how we handle this is a bit tricky as there are cases where we want the opposite behavior, but we're hoping to have a solution that can address both use-cases released soon.

@schaumb
Copy link
Contributor Author

schaumb commented Jul 20, 2021

While the linked issue is about a python run widget reappear event, here only a front-end modification happened (expander open and close ; beta expander "value" is not synchronized back to back-end, so no rerun happened).

So I am not really understand how related the issue.

@vdonato
Copy link
Collaborator

vdonato commented Jul 20, 2021

Ah, thanks for the clarification. This was my mistake -- I thought that the two issues looked similar so incorrectly assumed that they had the same root cause. You're right that these aren't related, and I'll investigate this bug this week or next if I have the bandwidth.

@vdonato
Copy link
Collaborator

vdonato commented Jul 23, 2021

Quick update: I took a bit of time to look into this, and it may be somewhat tricky to fix as when a file_uploader is hidden by the expander, we currently lose some of the file data that we'll need to properly re-render the file_uploader when it comes back into view.

Of course, the answer is to just store this data somewhere, but we'll want to do a bit of thinking to figure out where that best place is. I'll revisit this early next week when I'm able to ask some questions to people that are more familiar with this code

@kmcgrady kmcgrady added status:confirmed Bug has been confirmed by the Streamlit team priority:P2 labels Aug 4, 2021
vdonato added a commit to vdonato/streamlit that referenced this issue Aug 9, 2021
Currently, st.file_uploader and st.expander don't work well together as
the file_uploader widget loses its state (only on the frontend) when an
expander is closed and reopened. The reason for this is that we aren't
populating the initial value of a file_uploader widget if there's state
for the widget in the WidgetStateManager.

To fix this, we had to do a decent amount of extra work to send more
info about the file_uploader widget's state back to the server.
Previously, we somewhat hackily encoded all of the information in an
array of ints, where the first element in the array is the ID of the
most recently uploaded file, and the others are the IDs of the active
files. We now send a more descriptive proto back and forth, which
includes the max file ID in one field and a list of protos containing
the id/name/size of the uploaded files in another.

Closes streamlit#3557
vdonato added a commit that referenced this issue Aug 9, 2021
Currently, st.file_uploader and st.expander don't work well together as
the file_uploader widget loses its state (only on the frontend) when an
expander is closed and reopened. The reason for this is that we aren't
populating the initial value of a file_uploader widget if there's state
for the widget in the WidgetStateManager.

To fix this, we had to do a decent amount of extra work to send more
info about the file_uploader widget's state back to the server.
Previously, we somewhat hackily encoded all of the information in an
array of ints, where the first element in the array is the ID of the
most recently uploaded file, and the others are the IDs of the active
files. We now send a more descriptive proto back and forth, which
includes the max file ID in one field and a list of protos containing
the id/name/size of the uploaded files in another.

Closes #3557
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:P2 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants