I was wondering if there was a way to have a user upload a file (ie a txt or csv file) to a Streamlit app? I didn’t see anything in the docs about this.
Tangent from this, is it possible to inject HTML into Streamlit to create new functionalities?
Currently, there is no file picker, but I just added a feature request for one. Please feel free to follow this request on Github to follow its progress.
In the meantime, here’s an example of a janky ad-hoc file selector on the server:
import streamlit as st
import os
filename = st.text_input('Enter a file path:')
try:
with open(filename) as input:
st.text(input.read())
except FileNotFoundError:
st.error('File not found.')
#2: How to inject custom HTML into Streamlit
What would you like to add? Streamlit already supports many different elements and we’re adding more each day. If you share some details we can help you achieve your aim.
In the long run, we plan to expose a plug-in architecture. I’ve created this tracking bug. Please feel free to add comments describing what you’d like to see here.
Of course, these file selectors can be improved a lot, but these examples illustrate that fairly complex and useful UIs can be built using existing Streamlit primitives.
As for the HTML, I just thought that would be a quick way to add functionality that isn’t officially supported. For example a HTML element could help handle the scenario of a user uploading a file (imagine the case where the Streamlit app is hosted on AWS while the file is on a local directory).
Salim. Yes. The code we shared is a workaround for now. We will have to implement this feature request before you can get a full dialog. Please follow that request to get updates on when we implement it.
p.s. To help us do so quickly, could you please let us know if you would like:
To upload a file on the client (where you access Streamlit)
To upload a file on the server (where you ran streamlit run ...)
I’ve been thinking about this more now that my front end is deployed. What’s Streamlit’s general philosophy for web based applications where there may be a need for a user to upload data for prediction and/or download results?
For the uploader, we have this feature request, does this sound like it would be useful? For the downloader, we haven’t started a feature request for that yet, but we have been actively thinking about it, we’d love to get your input & ideas either here or through a new request on the GitHub.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
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.
Performance cookies
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.
Functional cookies
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.
Targeting cookies
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.