File upload does not clear cash

I am using the lates version of Streamlit 0.84.0 and I still get this problem of not being able to clear the cache after file upload and with a new file uploaded my app still uses the previous one.

Please let me know if there is a way to solve this.

Here is my code:


# Read CSV -> outputs Pandas Dataframe
def load_csv(ds):
	df_input = pd.DataFrame()
	df_input=pd.read_csv(ds)  
	return df_input

# CSV File uploader 
def file_upload():
	FILE_TYPES = ["CSV"]
	file = st.file_uploader("Upload file", type=FILE_TYPES)
	show_file = st.empty()
	if not file:
		show_file.info("Please upload a file of type: " + ", ".join(FILE_TYPES))
		return
	return file

my main():

file = file_upload()
		
		if file:
			if 'load_csv' in st.session_state:
				df=st.session_state.load_csv
				st.write(file.name + " " +  "is loaded") 

			else:
				df = load_csv(file)
				st.session_state.load_csv = df

			
		# Dataframe columns and types	
		if file:
			st.write("Columns and their types:")
			col = column_types(df)
			st.write(col)

			# Show Dataframe 
			st.text("Display uploaded dataframe")
			if st.checkbox("Show dataset"):
				st.dataframe(df)

And when a new file uploads even the dataset show button still shows the results from the previous uploaded dataset.

let me know if anyone have the same problem and could solve it :slight_smile:

Hi

Not sure I understand the problem here, I would expect the app to show the results of the csv file uploaded and the keep showing the the same results no matter how many csv files are uploaded after that.

Let me try an explain:

		if file:
			if 'load_csv' in st.session_state:
                # 'load_csv' will not be in session_state only for the first csv file
				df=st.session_state.load_csv
				st.write(file.name + " " +  "is loaded") 

			else:
                # since 'load_csv' is in session_state all other calls will end up here
				df = load_csv(file)
				st.session_state.load_csv = df

For what it’s worth, I am having the same problem. My Streamlit app is hosted on a server, and when I go to that server to upload a few files, the following steps of my app (sending data through a model and visualizing results) show results for the few files I uploaded as well as whatever else has been uploaded since the last time the app code was updated.