A download button with custom CSS

Hi @Chad_Mitchell

Thanks for the code above. It really helped. I am making a custom table component which already had a built in download button, so the auto download was just what I needed.

I was however having an issue of the filetype of the download. I was trying to download the file as excel and the browser didn’t interpret the base64 encoded string as excel.

Don’t know if it could help anyone but managed to find the right MIME type to make it work:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

if isinstance(df,pd.DataFrame):

            towrite = io.BytesIO()

            df.to_excel(towrite)  # write to BytesIO buffer

            towrite.seek(0)  # reset pointer

            b64 = base64.b64encode(towrite.read()).decode()  

        return f'<iframe width="1" height="1" frameborder="0" src="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}"</iframe>'