Downloading a csv file from rpivottable in Shiny

I am making a shiny dashboard that contains pivot tables and I want to be able to download the data from the edited pivot table into a csv file. Using downloadHandler and write.csv functions, I have successfully been able to download the data but it is saved into a file type "file" and can only be opened in a notepad, word document, or internet explorer because it is a list of values rather than a csv file. How can I change this to be a csv file?
Below is my code for the second half of the server, I got most of it from a stack overflow answer because I have been stumped. Help is greatly appreciated!

Clean the html and store as reactive

summarydf <- eventReactive(input$myData,{
  input$myData %>% 
    read_html %>% 
    html_table(fill = TRUE) %>% 
    .[[2]]
  
})

# show df as DT::datatable
output$aSummaryTable <- DT::renderDataTable({
  DT::datatable(summarydf(), rownames = FALSE)
})


output$downloadData <- downloadHandler(
  filename = "jobcost_pivotdata.csv",
  content = function(file) {
    write.csv(summarydf(), file, row.names = FALSE)
  }
)

Hi,

It seems that your summarydf() variable is likely not a data frame, judging by how it's constructed. Try wrapping it in a as.data.frame before you save it and see if it helps.

write.csv(as.data.frame(summarydf()), file, row.names = FALSE)

If not, please provide us with a slimmed down version of the full app and some dummy data so we can take a better look at it.

Grtz,
PJ