I have two selectbox’s, the first one is selecting directory, and the second one is selecting file under that directory selected by first selectbox. but always at the first time, after I select the file in the second selectbox, it will display the default files from the default directory by first selectbox. I have to select first one again, then works afterwards.
unfortunately, I can’t reproduce this bug. Can you maybe give more details on the specific setup of your app?
The following setup is working for me:
Folder structure
app.py
foo/foo1.txt
foo/foo2.txt
bar/bar1.txt
bar/bar2.txt
The app.py scripts looks like yours:
import streamlit as st
import pathlib
dict1 = {
pathlib.PurePath(d).name: d
for d in pathlib.Path(__file__).parent.iterdir()
if d.is_dir()
}
dict = st.selectbox('Directory', [*dict1])
files = {
pathlib.Path(f).stem: f
for f in pathlib.Path(dict).iterdir()
if f.is_file()
}
file = st.selectbox('Files', [*files])
sorry. i tried them as sidebar. no problem on pc, but it always happens at the first time on the server.
dict1 = {pathlib.PurePath(d).name: d for d in pathlib.Path(__file__).parent.iterdir() if d.is_dir()}
dict = st.sidebar.selectbox('please choose Directory', [*dict1])
files = {pathlib.Path(f).stem: f for f in pathlib.Path(dict).iterdir() if f.is_file()}
file = st.sidebar.selectbox('please choose files', [*files])
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.