For me, it is working perfectly with ppt file! Thanks a lot!
didntâ worked. Instead showed this bunch of data from my dataframe and no button to be clicked and downloadâŠ
1 1 0.223607 2 2 0.087706 3 3 0.111803 4 4 0.141421 5 5 0.182574 6 6 0.223607 7 7 0.182574 8 8 0.119523 9 9 0.087706 10 10 0.223607 11 11 0.111803 12 12 0.141421 13 13 0.182574 14 14 0.119523 15 15 0.100000 16 16 0.076696 17 17 0.141421 18 18 0.091287 19 19 0.081650 20 20 0.111803.csv" class= "" id="efbcacbabbfddfcee" href="data:file/txt;base64,U2FtcGxlcyxDZyBJbmRleA0KMSwwLjIyMzYwNjc5Nzc0OTg2NDU4DQoyLDAuMDg3NzA1ODAxOTMwNzAzNg0KMywwLjExMTgwMzM5ODg3NDk3Njk5DQo0LDAuMTQxNDIxMzU2MjM3Mjg3MzgNCjUsMC4xODI1NzQxODU4MzUwOTE3DQo2LDAuMjIzNjA2Nzk3NzUwMDIzNDgNCjcsMC4xODI1NzQxODU4MzQ5NjE5Ng0KOCwwLjExOTUyMjg2MDkzMzQxNDYyDQo5LDAuMDg3NzA1ODAxOTMwNzAxMg0KMTAsMC4yMjM2MDY3OTc3NDk4NjQ1OA0KMTEsMC4xMTE4MDMzOTg4NzQ5NjcwNg0KMTIsMC4xNDE0MjEzNTYyMzcyODczOA0KMTMsMC4xODI1NzQxODU4MzUwOTE3DQoxNCwwLjExOTUyMjg2MDkzMzQyNjczDQoxNSwwLjA5OTk5OTk5OTk5OTk4NDM3DQoxNiwwLjA3NjY5NjQ5ODg4NDczNDY4DQoxNywwLjE0MTQyMTM1NjIzNzI4NzM4DQoxOCwwLjA5MTI4NzA5MjkxNzUyMTUzDQoxOSwwLjA4MTY0OTY1ODA5Mjc2OTUNCjIwLDAuMTExODAzMzk4ODc0OTY3MDQNCg==">Donwload Spreedsheet
Did you write this code in the place where you want to have the button?
tmp_download_link = download_button(df_to_save.reset_index(), f'{file_name}.csv',
button_text='Click here to download your text!')
st.markdown(tmp_download_link, unsafe_allow_html=True)
Did you create folder .streamlit in your project and then config.toml in it with following code?
[theme]
# should look like a light theme
primaryColor = '#f43365'
backgroundColor = '#000000'
secondaryBackgroundColor = '#f1f3f6'
textColor = '#000000'
font = 'sans serif'
And the code that is describing the button from here?
I donât understand what do you mean
@czubert
I didnât know was need to create this folder. But now i did and still didnât worked.
and also put the code from here streamlit download button ($2106399) · Snippets · Snippets · GitLab and the part where i want located the donwload_button at the main code:
tmp_download_link = download_button(df4,f'{cg_result}.csv', button_text='Donwload Cg Dataframe')
st.markdown(tmp_download_link, unsafe_allow_html=True)
where:
df4
is the dataframe i want to able the user donwload
cg_result
the filename i want to show to the user
you have file âconfig.toml.txtâ and it should be âconfig.tomlâ
Try it
didnât worked!
Button code:
tmp_download_link = download_button(df4,f'{file_name}.csv', button_text='Donwload Cg Dataframe')
st.markdown(tmp_download_link, unsafe_allow_html=True)
returned the following error. Seems like where the file_name (which is a string) should be the name of the file and is getting a problem, idk why.
it is not a string, when you use {} inside of f â â string it is a variable that becomes a string it might be also an int
for example
file_name = 2312312313
print(f"{file_name}.csv")
prints â2312312313.csvâ
filename is a variable that you should define earlier, or just write the name of the file without curly braces
Worked as expected . BTW how can i change the button colors and put the same style as streamlit standard button have in light mode?
in the snippet, part of the code looks like this:
prim_color = st.config.get_option('theme.primaryColor') or '#F43365'
bg_color = st.config.get_option('theme.backgroundColor') or '#000000'
sbg_color = st.config.get_option('theme.secondaryBackgroundColor') or '#f1f3f6'
txt_color = st.config.get_option('theme.textColor') or '#000000'
font = st.config.get_option('theme.font') or 'sans serif'
st.config.get⊠takes colors from the file âconfig.tomlâ, so if you define colors in config toml, your button will get the same colors as the rest of the layout (there are some differences in streamlit, and for example upload files button have different colors from other buttons)
Ok, but when i do some changes at colors didnât bring the same expect as i have in streamlit stardand style button (also the border color in grey i think)
My donwload button, as you can see, donât have the border colorâŠ
you need to check which part of this code:
prim_color = st.config.get_option('theme.primaryColor') or '#F43365'
bg_color = st.config.get_option('theme.backgroundColor') or '#000000'
sbg_color = st.config.get_option('theme.secondaryBackgroundColor') or '#f1f3f6'
txt_color = st.config.get_option('theme.textColor') or '#000000'
font = st.config.get_option('theme.font') or 'sans serif'
is responsible for what. you can only change sets of colors.
primaryColor='#6C9BC0' # radiobuttons etc
backgroundColor="#FFFFFF" # Main color
secondaryBackgroundColor="#d3d4db" # sidebar color
textColor="#262730"
font="sans serif"
Ok, thanks a lot for your help!
No worries happy to help!
yes, you can change âfâ{file_name}.csvââ into âfâ{file_name}.xlsxâ , in that way, you can download xlsx file.
@BeyondMyself I tried this but when i press the button to download, and go to excel to open the file, i get a error saying the file are corrupted or are in different extension
tmp_download_link = download_button(cg_result_dataframe, f'cg_result_dataframe.xlsx', button_text='Donwload Cg Dataframe đŸ')
and the code @czubert make available, only let the user download the file in csv or txt extension. As shows here:
"""
Generates a link to download the given object_to_download.
Params:
------
object_to_download: The object to be downloaded.
download_filename (str): filename and extension of file. e.g. mydata.csv,
some_txt_output.txt
download_link_text (str): Text to display for download
link.
button_text (str): Text to display on download button (e.g. 'click here to download file')
pickle_it (bool): If True, pickle file.
Returns:
-------
(str): the anchor tag to download object_to_download
Examples:
--------
download_link(your_df, 'YOUR_DF.csv', 'Click to download data!')
download_link(your_str, 'YOUR_STRING.txt', 'Click to download text!')
"""
As you may see in the download_button function, there is an if alse statement if picle_it, inside else statement there is another if else statement in which it checks the distance.
elif isinstance(object_to_download, pd.DataFrame):
object_to_download = object_to_download.to_csv(index=False)
you can see that there is written that if instance is pd.DataFrame, then you should use method âto_csvâ
you need to change it to: pd.dataframe.to_excel() for more info check it here:pandas.DataFrame.to_excel â pandas 1.2.4 documentation
I hope it will work for you
I did those changes you said but didnât worked. Instead, returned the following error:
elif isinstance(object_to_download, pd.DataFrame):
object_to_download = object_to_download.to_excel(index=False)
i also changed the donwload_button extesion:
tmp_download_link = download_button(cg_result_dataframe, f'cg_result_dataframe.xlsx', button_text='Donwload Cg Dataframe đŸ')