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.
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.