I'm making a Streamlit attendance app, all the attendance excel sheets are uploaded to cloud storage (Google cloud storage in my case). How do I view all the available files(which are named date-wise) and allow a st.selectbox() to allow to view the available files and select them one at a time to work with?
I've read the following docs and threads and got the basics working but am not sure how to implement the dropdown list as streamlit selectbox for the implementation of the same.
My current way of getting files to my app is via upload: https://i.stack.imgur.com/NHmxT.jpg
uploaded_file = st.file_uploader(label='upload your csv or excel file', type=['csv', 'xlsx'])
So, I want to keep all the files (which will be named in DDMMYYYY format) in a cloud server. I want to have a dropdown selection st.selectbox() for the different available filenames (which exist in a date format) and get input from the cloud storage in the Streamlit app.
import streamlit as st
from google.oauth2 import service_account
from google.cloud import storage
# Create API client.
credentials = service_account.Credentials.from_service_account_info(
st.secrets["gcp_service_account"]
)
client = storage.Client(credentials=credentials)
# Retrieve file contents.
# Uses st.experimental_memo to only rerun when the query changes or after 10 min.
@st.experimental_memo(ttl=600)
def read_file(bucket_name, file_path):
bucket = client.bucket(bucket_name)
content = bucket.blob(file_path).download_as_string().decode("utf-8")
return content
bucket_name = "streamlit-bucket"
file_path = "myfile.xlsx" #Edit the input variable here.
Instead of file_path being a constant, I want it to be a st.selectbox() which will fetch the available files from streamlit-bucket. The files stored there will be in the naming convention of DDMMYYYY (as it'll have attendance files of different dates). After which it'll be stored in the variable content and I can then start working with it.
content = read_file(bucket_name, file_path)`
My Source code for this above google cloud storage implementation is from the following link: https://docs.streamlit.io/knowledge-base/tutorials/databases/gcs#enable-the-google-cloud-storage-api
my sources and references so far:
https://www.codegrepper.com/code-examples/python/drop+down+menu+streamlit
https://discuss.streamlit.io/t/file-list-in-upload-directory/15796