I was using this snippet for folder uploading until I started getting an error where I was not able to make an executable for the application, the error seems to be related to this: Tkinter issue
Here’s my code snippet:
import streamlit as st
import tkinter as tk
from tkinter import filedialog
# Set up tkinter
root = tk.Tk()
root.withdraw()
# Make folder picker dialog appear on top of other windows
root.wm_attributes('-topmost', 1)
# Folder picker button
st.title('Folder Picker')
st.write('Please select a folder:')
clicked = st.button('Folder Picker')
if clicked:
dirname = st.text_input('Selected folder:', filedialog.askdirectory(master=root))
I understand your code, but I don’t know for sure what you want. Being able to upload a folder? Being able to get the path to a folder, as the code does? Having a dedicated directory picker that doesn’t distract the user with other file names?
I only have an answer for the first one. You might be able to use HTML, javascript and the components API for the other two. But I have never seen anything like that so it might not be possible.
You cannot select a directory, but you can drag and drop a directory into the file uploader. That will result in the whole directory being uploaded so it fits the bill for being able to upload a folder.
For selecting a directory (directory picker), the only solution I know is the one you posted in the OP. But that can only work if the application and the browser are running in the same computer.