I have a python code to create an excel file with multiple sheets from data frame.
The below is working as expected in local but when the code is deployed to beta and production. The initial 2 to 4 clicks are not downloading the file into machine later its downloading the file content.
Code
@st.cache_data(ttl=300)
def create_text_preference_excel_data(df1, df2, df3, df4, df5, df6):
“”"
Save multiple DataFrames to an Excel file with separate sheets.
“”"
output = io.BytesIO()
with pd.ExcelWriter(output, engine=‘xlsxwriter’, engine_kwargs={‘options’: {‘in_memory’: True}}) as writer:
df1.to_excel(writer, sheet_name=‘WorkItem Level Feedback’, index=False)
df2.to_excel(writer, sheet_name=‘Summary’, index=False, header=False, startrow=0, startcol=0)
df3.to_excel(writer, sheet_name=‘Summary’, index=False, header=False,
startrow=len(df2) + 3, startcol=0)
df4.to_excel(writer, sheet_name=‘Summary’, index=False, header=True, startrow=len(df2) + len(df3) + 4, startcol=0)
df5.to_excel(writer, sheet_name=‘Summary’, index=False, header=True, startrow=len(df2) + len(df3) + len(df4) + 5, startcol=0)
df6.to_excel(writer, sheet_name=‘Summary’, index=False, header=True, startrow=len(df2) + len(df3) + len(df4) + len(df5) + 7, startcol=0)
return output.getvalue()
excel_data = create_text_preference_excel_data(df1, df2, df3, df4, df5, df6)
left, right = st.columns([0.87, 0.13])
with right:
st.download_button(
label="**Export Report**",
data=excel_data,
file_name="report.xlsx",
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
disabled=st.session_state.disabled_buttons
)
Error Message
In Chrome Browser - File wasn’t available on the site
In Firefox Browser - File Not found error
Versions
Streamlit Version - 1.31.0
Python Version - 3.9
The same code works with 100% reliability locally but once its deployed via aws cloud its not downloading the file in initial clicks and later after some time its downloading the file.
Your help is highly appreciated.
Thanks.