Any news about this topic ? Did you managed to create something ?
Not yet, the work around was to create an export button that generate a csv instead of actually copying the dataframe.
Hope it helps:
csv = df_export.to_csv(index=False)
b64 = base64.b64encode(csv.encode()).decode()
# st.markdown('### **ā¬ļø Download output CSV File **')
href = f'<a class="streamlit-button small-button"
href="data:file/csv;base64,{b64}" download="{df_export.columns[0]}.csv">Export</a>'
st.markdown(href, unsafe_allow_html=True)
My objective was to export this clipboard to excel, i didnāt find a easy way to use clipboard, instead iām downloading df as xlsx and use it to copy for my sheets.
I used Heroku to deploy this app, so using href didnāt work, i think something related to VM used⦠So i used new function st.download_button and itās works
I managed that with this:
# Function to convert csv to xlsx
@st.cache
def to_excel(df):
output = BytesIO()
writer = pd.ExcelWriter(output, engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1',index=False)
writer.save()
processed_data = output.getvalue()
return processed_data
This function i get from one topic ⦠And to download itā¦
df= to_excel(df)
st.download_button(label="Download",data=df,file_name='df.xlsx')
See if could be useful for youā¦
Best Regards.
How do I identify and throw a message if the data has been copied using this. For example: Once a person click on the button, Can I throw some kind of message saying dataframe as been copied?
Hi!
This works well for me (on windows):
import pyperclip
# Your code ...#
pyperclip.copy(my_dataframe.to_csv())
I think pyperclip doesnāt work when the app is run on streamlit. At least, it didnāt work for me! Any solution is appreciated.
I think this will only work if you are running on your local. If you deploy that on a server, pyperclip
will try to use the server processās clipboard instead of the one the userās browser is running in. If it works at all, it will be uselessly sitting in a clipboard in a headless process on a server, not your local clipboard.
The current dataframe version supports copy to clipboard of all columns which I believe solves the question of the topic. You can find some information here.
Unless I am missing something, this is not really convenient for large dataframes, say > 1000 rows.
You can select all cells (CMD + A) and copy them to the clipboard. But I think for larger data, a download option would be better option for this usecase.
That shortcut is what I was missing and it is good enough for me.
Hi! It works indeed, however, what I find not very convenient is that you canāt copy the column names in this way. Only via loading a .csv file, which we donāt want to do, when we want to copy just a little bit of the values.
We would like it much better with an ability to choose and copy the column names as well.