Question:
I am working with streamlit in python to produce a tool that takes a user’s input of a csv filename, and then carries out cleaning/tabulating of the data within the file.I have encountered an issue where before the user has entered their filename, my streamlit site shows a “FileNotFoundError: [Errno 2] No such file or directory:”
This is expected because the user has not entered their filename yet – however once filename is entered the code runs smoothly. I am hoping to overcome this issue but as a relative newcomer to Python I am quite unsure how!
Please see code snippet below
Answer:
The general pattern for both Streamlit and Python in general is to test for the value existing:autocall_gbp_file
is None
. By writing if autocall_gbp_file:
, you’re only running the pandas read_csv
after someone has entered a value.Separately, you’re better off developing this with
st.file_uploader
than using text_input
, as the Streamlit app doesn’t necessarily have access to the user filesystem and same drive mapping as the machine you are developing on. By using st.file_uploader
, you’re literally providing the actual file, not a reference to where it might be located.If you have better answer, please add a comment about this, thank you!