Hi all does anyone have any examples of workarounds or packages for a multi select uploaded files widget, with some files able to be selected and not others (for instance, to be processed by Python functions)?
Hey @lalau66,
Thanks for sharing this question! Can you elaborate a little more on the functionality youāre trying to accomplish? Are you looking to upload multiple files and then only use some of those files? Some additional details about the use case will help us get you an answer as soon as possible
Hi. Iām not the original poster of this question but it sounds like I am trying to do the same thing as lalau66. I need to present a list of files in a known directory. From that list the user can select one or more files in the list and then perform some action on those files. I came close with ag-grid but hit a road block when I couldnāt get the list head (ie the label on top of the list) to be the same width as the list itself. It is a single column grid with a column header. Iām hoping for a solution to that problem OR a solution other than ag-grid. The attached image shows the list of files with the oversized header and the list as it needs to appear. Any insight to a solution would be very helpful⦠thanks
If it was me, I would just do a series of st.checkbox items with each file type ā does that not work for you?
Hmm? Very interesting⦠They would need to be within a scrollable container, which one would think would be relatively straight forward to implement. There may be 500+ files to be listed. Thanks for the idea⦠Iāll give that a shot.
Hereās one way to accomplish it with one of the latest additions to streamlit-extras, stylable_container
import streamlit as st
from streamlit_extras.stylable_container import stylable_container
files = st.file_uploader("Choose some files", accept_multiple_files=True)
with stylable_container(
key="scrollable_container",
css_styles="""
{
max-height: 200px;
overflow-y: scroll;
}
""",
):
for file in files:
st.checkbox(file.name)
Thanks⦠Looks like thatās the way to go with this. However Iām running into the problem that when the script is run again from the top (which it does a lot) it recreates the checkboxes all over again and of course there are duplicate widgets then. But if I donāt recreate them, they vanish. Hereās what I have:
Iām sure itās going to be some stupid thing I am overlooking. This is frustrating since I have been writing software for 25 years -mostly C, Swift, Objective C. All this stuff seems like it should be so easyā¦Somehow I have a mental block trying to grasp the flow of things and the scope of objects.
import streamlit as st
import csv
from streamlit_extras.stylable_container import stylable_container
def read_csv(filename):
with open(filename, ārā) as f:
reader = csv.reader(f)
return list(reader)
def get_selectedCBS():
for i in st.session_state.namelist:
if st.session_state[i] == True:
st.caption(f"Checkbox {i} was pressedā¦")
def loadlists():
filelist = read_csv(āairlines.csvā)
for i in filelist:
st.session_state.namelist.append(i[0])
def main():
if ānamelistā not in st.session_state:
st.session_state.namelist =
if "loaded" not in st.session_state:
st.session_state.loaded = False
loadlists()
if "skip" not in st.session_state:
st.session_state.skip = False
with stylable_container(
key="scrollable_container",
css_styles="""
{
border: 1px solid rgba(49, 51, 63, 0.2);
box-shadow: 3px 3px #888888;
max-height: 200px;
max-width: 150px;
overflow-y: scroll;
}
""",
):
if(st.session_state.skip == False):
st.session_state.skip = True
for name in st.session_state.namelist:
label = name
mykey = name
st.checkbox(label, key=mykey)
if st.button("test"):
get_selectedCBS()
if name == āmainā:
main()
Could you please repost that code inside a code block (surrounded by ```)?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.