from pathlib import Path
from s3fs import S3FileSystem as s3
# @st.cache(ttl=2)
def get_run_names():
"""List existing run names"""
BASE_PATH = "[INSERT_S3_DIRECTORY_HERE]"
run_names = [Path(file).stem for file in s3().ls(BASE_PATH)]
if st.button("Click to Refresh!"):
del run_names
run_names = [Path(file).stem for file in s3().ls(BASE_PATH)]
return run_names
When I click the “Click to Refresh!” button, I still get the same list of files even though the directory has changed and when I run this gist in the terminal, it gives me the proper directory list.
Just to confirm that detail, you commented the @st.cache line during your tests?
Does the list update when you press R to refresh the page? And when you press F5?
Also, when you click the update button, the whole script re-runs. That means the first run_names line is executed, and as you pressed the button, the second run_names line is executed as well.
Well, the only explanation I have is that S3FileSystem caches your result to avoid sending too many requests. I’ve come across the clear_instance_cache() in S3Fs documentation. Maybe you could try calling that after your ls(). If it doesn’t work, I saw other options related to caching in the same page. You could try to play with those as well.