Summary
right now i have an application that allows user to upload using streamlit default widget , which can be a bit bulky , however i want to have a small regular button that after clicking it just triggers the fileuploader explorer
right now i have an application that allows user to upload using streamlit default widget , which can be a bit bulky , however i want to have a small regular button that after clicking it just triggers the fileuploader explorer
At the moment, I’m not aware of any other options (even on the component side) to implement a smaller file uploader in Streamlit.
Now, if you wanted to give it a whirl, you could build your own file uploader widget!
For that, you’d need to create a bidirectional component. We have a pretty good guide on building components and even have templates available here.
Good luck, and let us know if you have any more questions along the way.
Best,
Charly
Hey @Charly_Wargnier and thank you for your time
okay what about the ability to trigger the file explorer to open up , ie triggering the st.file_uploader as if there were an interaction but without the user clicking it
You’re welcome.
Could you please elaborate? I’m not sure I’m following you.
Best,
Charly
what I meant is, is it possible to trigger the file uploader programmatically , ie to simulate a user click on that object , so basically if a user clicks on a random button ( lets call it button1 = st.button(‘button1’) , that button triggers the widget from st.file_uploader directly to the file explorer , as if he clicked on st.file_uploader himself
Thank you, @tarek-kerbedj, for the additional info.
Although I’m not aware of a way to interact with the file uploader programmatically, you’re certainly able to conditionally display the file uploader widget based on another action or condition. For instance, clicking a specific button could trigger the appearance of the file uploader.
I hope this helps,
Charly
Does something like this is what you’re looking for?
import streamlit as st
import time
chat_box = st.chat_input("What do you want to do?")
if "uploader_visible" not in st.session_state:
st.session_state["uploader_visible"] = False
def show_upload(state:bool):
st.session_state["uploader_visible"] = state
with st.chat_message("system"):
cols= st.columns((3,1,1))
cols[0].write("Do you want to upload a file?")
cols[1].button("yes", use_container_width=True, on_click=show_upload, args=[True])
cols[2].button("no", use_container_width=True, on_click=show_upload, args=[False])
if st.session_state["uploader_visible"]:
with st.chat_message("system"):
file = st.file_uploader("Upload your data")
if file:
with st.spinner("Processing your file"):
time.sleep(5) #<- dummy wait for demo.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
Super useful, Carlos, thank you!
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.