I tried to create a download_button:
st.sidebar.download_button(label=‘Download’,data=‘grades.csv’,file_name=‘grades.csv’,mime=‘text/csv’)
I got an error: streamlit.errors.StreamlitAPIException: ‘download_button()’ is not a valid Streamlit command.
Hi @Gad_Halevy
It seems that you want to have allow users to download the grades.csv file. But it seems the grades.csv file was not yet read in.
Thus, can you try reading contents from the CSV file using pandas pd.read_csv()
and assign it to a variable df
. Next, use df
as the input argument for the st.download_button()
:
import streamlit as st
import pandas as pd
df = pd.read_csv(‘grades.csv’)
st.download_button(label=‘Download’,data=df, file_name=‘grades.csv’, mime=‘text/csv’)
Hope this helps!
Best regards,
Chanin
Thanks dataproffessor, you are right that I had to read the file first, but I still got the same error, it works fine from my computer but not from streamlit cloud.
Usually if there is some problem with a file that works locally but not in the cloud, there’s either a local file that needs to be copied to the cloud, or a file path that needs to be made OS-agnostic (e.g. use forward slashes instead of back slashes)
Can you link to your repository?
The application link
Hi Debbie;
This is the line of code:
st.sidebar.download_button(label=‘Download Grades’,data=df, file_name=‘grades.csv’, mime=‘text/csv’)
The file ‘grades.csv’ was created and saved during the application run.
Created: groups.to_csv(‘grades.csv’, index=False)
During the run I read it: groups=pd.read_csv(‘grades.csv’)
All done with no problem but when I tried this line of code:
st.sidebar.download_button(label=‘Download Grades’,data=df, file_name=‘grades.csv’, mime=‘text/csv’) I get an error:
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.