How to display filelist in collapse state using os module

Question:

I am trying to display file list in collapse state and couldn’t find a solution. After running the app, it always display in opened file list which is messy in user’s eye.
if you guys have any idea on how to achieve it, would help 🙂

code i am using:

import os
import streamlit as st

st.write('  1 docx-raw')
filelist = []
for root, dirs, files in os.walk("/home/lungsang/Desktop/levelpack-UI/content/A0/1 docx-raw"):
    for file in files:
        filename = os.path.join(root, file)
        filelist.append(filename)
st.write(filelist)

How it displays :
how it displays currently

Desired displays in collapse state:

collapse state

Asked By: lungsang

||

Answers:

You can use st.expander() to accomplish that task.

filelist = []
for root, dirs, files in os.walk("/home/lungsang/Desktop/levelpack-UI/content/A0/1 docx-raw"):
    for file in files:
        filename = os.path.join(root, file)
        filelist.append(filename)
with st.expander("  1 docx-raw"):
    st.write(filelist)
Answered By: Jamiu Shaibu