Uploading Local Files to a WebApp

Hey guys,

So, I am wondering if anyone has successfully been able to load a dataframe/file from your local machine to a web app?
I built this application that takes in a dataset/csv file from my C: drive. I have a selectbox on the sidebar that selects the file to be loaded and then it performs some EDA. I works as intended on my machine but when I deploy it on heroku-- it is not able to access the files.

Hereโ€™s a screenshot of the app when the file is loaded on my localhost:

I printed the CWD for troubleshooting purposes and it looks good on my machine.

This is what I get when I run it on heroku:

As you can see, the app is not able to find the local directory that I am providing.

The code to retrieve the file from my C: drive is as follows (#ignore commented out lines as I was using them to try to figure out what the problem was)

    st.write(os.getcwd())
    #os.chdir(r"C:\Users\us1145\Desktop\DataFrames/")
    #home = os.environ
    #st.write(home)
    #st.write(os.getcwd())
    path_to_file = (r"C:\Users\us1145\Desktop\DataFrames/")
    file_list = [f for f in listdir(path_to_file) if isfile(join(path_to_file, f))]
    file_select = st.sidebar.selectbox("Select a file", file_list)
    st.sidebar.title("Load Dataset")
    if st.sidebar.button("Click to load data"):
        with st.spinner("Loading "+ file_select + " ..."):
            time.sleep(20)
        st.success("File loaded!")

Any help would be greatly appreciated!

GM

1 Like

Hi @gabe_maldonado

Your code wonโ€™t work because itโ€™s executed on the server at Heroku. It does not have access to your local c: drive.

Butโ€ฆ There is a file uploader widget in progress. You can read more there Upload Files to Streamlit App. In that thread there is also a description of temporary solution using the Droopy file upload server.

Marc

1 Like

Thank you so much for getting back to me, @Marc.
Iโ€™m looking forward to see that file uploader implemented.
GM

1 Like