Zoe2
October 7, 2024, 7:10pm
1
Hey - I am having trouble accessing the setting behind the close button (‘x’) in the file uploader.
I need the session state to be clear if user closes the current file. Currently, when i click ‘x’ and upload a new one, the file wont be rewritten.
Thanks!
3 Likes
Also would like to know how to do this
1 Like
Yixian
October 7, 2024, 7:38pm
3
I’m running into the same problem. Is there any solution to it?
1 Like
Jos3
October 7, 2024, 8:31pm
5
Also have the same question here
1 Like
ayca
October 8, 2024, 11:08am
6
I want to learn this as well…
1 Like
Hi @Zoe2 , welcome to the forum!
You can make sure the session state gets updated by adding a key to the file uploader, like this:
st.file_uploader("Upload a file", key="file_uploader")
# See the current value like this:
st.write(st.session_state.file_uploader)
Zoe2
October 8, 2024, 2:28pm
8
Thanks, what if the widget is defined as a variable to be used further like
variable_df = st.file_uploader()
The same solution works just fine
You can also access the currently-uploaded file via st.session_state.file_uploader if you set file_uploader as the key, even if you don’t assign the output to a variable directly.
1 Like
system
Closed
April 6, 2025, 2:58pm
10
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.