We also continue to keep in touch over email, but just to keep any other readers up to date, here is a summary of our discussion:
Thank you for getting in touch - I’m really pleased to hear you have enjoyed ContainDS Desktop!
I think the important piece of information you are missing is that the ‘workspace folder’ on your computer maps to the path ‘/app’ inside the Docker container.
So for example, on my Mac the container is running with a workspace of /Users/dan/streamlit-single and this can be accessed via /app in the container’s Streamlit code.
Here is my example folder on the Mac:
|- code.py
|- csvfiles
|- test.csv
|- testboxes.csv
My version of the Python code is at the end of this email, showing two methods of accessing the files - direct access through Python code, and then using st.file_uploader.
For the direct access method (not using st.file_uploader) it is important to understand that most of your computer’s hard drive is not accessible directly by the container. That is essential for security. So the csv files should ideally be in your workspace folder (as mine are above). You could always use a symlink if you really wanted to store them elsewhere on your hard drive.
Rather than expect the user to know that /app is the location for accessing the workspace from inside the container, in my example code I just expect them to type the immediate subfolder name of ‘csvfiles’ and then I prepend ‘/app/’ to that. In fact, if you just want to find all csv files in the workspace then you could just glob from the /app folder recursively anyway, so you don’t really need to specify the subfolder name.
For the file uploader version, I’m not too sure why you were seeing the 405 error. It seems to work for me using the streamlit-single Docker image, but I do see the 405 error using streamlit-launchpad images. I’ll take a look.
–
import streamlit as st
import glob
from os import path
import pandas as pd
st.markdown('# Based on subfolder path')
path_input_data = st.sidebar.text_input("Provide the name to the subfolder in which your csv files are "
"stored.")
st.write("Input path:", path_input_data)
docker_search_path = path.join('/app', path_input_data)
st.write("Search path:", docker_search_path)
if path_input_data:
excel_files = glob.glob(docker_search_path + '/**/*.csv', recursive=True)
st.write(excel_files)
st.markdown('# Now try uploading')
uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
if uploaded_file is not None:
st.write('Uploaded file: ', uploaded_file)
data = pd.read_csv(uploaded_file)
st.write(data)
st.write('Streamlit version: ', st.version._get_installed_streamlit_version())
