pragmatic-streamlit / streamlit-file-browser

Streamlit file browser
89 stars 13 forks source link

Update frequency of the file browser #41

Open enrico-stauss opened 1 week ago

enrico-stauss commented 1 week ago

Hi,

I'm using this component to browse a set of files that are created by the running application. Unfortunately I noticed, that freshly created files do not show up immediately when nagivating the file browser. I also do not now how to trigger a rebuild of the file tree. Sometimes they just show up after a bit.

I already made sure that the caching option is set to False and from looking into the python backend in init.py, I cannot directly understand why freshly added files are not picked up. I'm not using any of {use_static_file_server, artifacts_site, or artifacts_download_site}.

Can you help me out with this?

Thank you and kind regards!

y805939188 commented 1 week ago

Hi,

I'm using this component to browse a set of files that are created by the running application. Unfortunately I noticed, that freshly created files do not show up immediately when nagivating the file browser. I also do not now how to trigger a rebuild of the file tree. Sometimes they just show up after a bit.

I already made sure that the caching option is set to False and from looking into the python backend in init.py, I cannot directly understand why freshly added files are not picked up. I'm not using any of {use_static_file_server, artifacts_site, or artifacts_download_site}.

Can you help me out with this?

Thank you and kind regards!

Hi, In our scenario, we used a streamlit component named streamlit_autorefresh(from streamlit_autorefresh import st_autorefresh) to refresh: img_v3_02c8_c403ccff-6723-4f34-8c51-20f4ed77727g Can you see if this way can satisfy your demand?

enrico-stauss commented 1 week ago

I gave it a try but unfortunately it is not satisfactory. My usecase for your component is quite simple though, I like the idea and the fact that it is plug-and-play but I may just revert to implementing the functionality directly in streamlit myself.

y805939188 commented 1 week ago

I gave it a try but unfortunately it is not satisfactory. My usecase for your component is quite simple though, I like the idea and the fact that it is plug-and-play but I may just revert to implementing the functionality directly in streamlit myself.

Ok~ Otherwise, Could you provide me with a simple code example to illustrate your scenario? I might consider a way to support it in my leisure time.

enrico-stauss commented 1 day ago

I can provide you with a brief MWE for it:

import os
import streamlit as st
from streamlit_file_browser import st_file_browser

BASE_DIRECTORY = "tmp_dir"
os.makedirs(BASE_DIRECTORY, exist_ok=True)

left, right = st.columns(2)

with left, st.form("file_input", clear_on_submit=True):
    file_name = st.text_input("file name")
    file_content = st.text_area("file content")
    submitted = st.form_submit_button("Create")
    if submitted:
        with open(os.path.join(BASE_DIRECTORY, file_name), "x") as fp:
            fp.write(file_content)

with right:
    st_file_browser(
        BASE_DIRECTORY,
        key="test",
        show_choose_file=False,
        show_delete_file=False,
        use_static_file_server=False,
        show_download_file=True,
        show_new_folder=False,
        show_upload_file=False,
        show_preview=True,
        use_cache=False,
    )

Kind regards Enrico