I need that only the single file to be displayed here, because others are duplicates.
It would be great if you also tell me how to clean file_uploader session of duplicates.
I need that only the single file to be displayed here, because others are duplicates.
Hi @intolighter,
The only way to remove an uploaded file without exiting or refreshing the app is for the user to click the “x” button – in other words, this isn’t possible programmatically.
Caroline
Hi @intolighter,
This could be solved by resetting uploader’s key every time after upload
import streamlit as st
if 'ctr' not in st.session_state:
st.session_state['ctr'] = 0
if 'docs' not in st.session_state:
st.session_state['docs'] = []
def uploader_callback():
if st.session_state[st.session_state['ctr']] is not None:
new_files = st.session_state[st.session_state['ctr']]
for i in new_files:
st.session_state['docs'].append(i.name)
st.session_state['ctr'] += 1
st.file_uploader(
label="File uploader", on_change=uploader_callback, key=st.session_state['ctr'], accept_multiple_files= True
)
st.write(st.session_state)
And streamlit automatically forgets old keys so no need to worry about that also
Hi @intolighter
Programmatically, there’s no way to remove an uploaded file without requiring the user to click the “x” button. This means that you must manually interact with the interface to delete the file, and it cannot be done automatically through code. So it’s an easy step to follow.
Hope it will help you
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.