Download Button for Excel file


How can I make a function button to download a DataFrame in Excel format (.xls)?

I have this DF:

UI Code:


 downloadButton("downloadData", "Baixar Planilha de Dados"),


output$contents2 = DT::renderDataTable({

... code for download the dataTable that i don't know how to do

I tried to follow the example from "' but it did not work.

Can someone help?


Since you're already using a DataTable, try looking into adding the Buttons extension which allows you to download the data in the table. See this


If a CSV file is "good enough" Excel for you - you can consider this in your server side code:

 # pres download data -> initiate save csv
   output$downloadData <- downloadHandler(
     filename = "downloaded_data.csv",
     content = function(file) write.csv2(times, file, row.names = F),  # replace "times" with your data.frame to export'
     contentType = "text/csv"

A side note: download buttons are known to behave strangely in Shiny preview (don't ask me why) so be sure to try troubleshoot it live.

Also consider between write.csv and write.csv2 depending on your formatting customs (coma for separator or decimal places and so on...)


Really thanks, both of you, @jlacko and @jdb

It works!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.