Multi select uploaded files widget

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 :slightly_smiling_face:

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.

1 Like

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)
3 Likes

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.