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.