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)
}
)