Unable to export the output data as csv / excel from ShinyApp using rpivotTable

Hi guys,
I'm using rpivotTables Shinyapp to export the pivottable data as csv, excel, pdf using buttons (Note: I don't want to export the actual data). The data is shown in the image. However i'm unable to do so, can't figure out the reason due to my limited knowledge. I shall be really thankful for the help :slight_smile:
Kind regards

library(rpivotTable)
library(dplyr)
library(readr)
library(shiny)

#ui
ui = fluidPage(
  radioButtons(inputId="file", label="Enter the format to download", 
               choices=c("none", "csv", "excel", "pdf", "copy"), inline = TRUE, selected="none"),
  
  selectInput(inputId = "vs", label = "vs:", choices = c("All", 
                                                         unique(as.character(mtcars$vs)))),
  
  fluidRow( rpivotTableOutput("pivot")))


#server
server = function(input, output, session) { 
  reactive({
    mtcars %>% select(cyl, carb, vs, mpg) %>% group_by(carb,vs ) %>% 
      summarise(mpg=sum(mpg)) }) 
  
  output$pivot <- renderRpivotTable( rpivotTable::rpivotTable( rows = c( 
    "vs"),cols=c("carb"),vals =  "mpg", aggregatorName = "Sum",rendererName =  
      "Table",width="50%", height="550px",
    {
      data <- mtcars
      
      if(input$vs != 'All') {
        data<-data[data$vs == input$vs, ]}
      
      if(input$file =="csv") {
        write_csv(filename = data,'data.csv')}
      
      else if (input$file=="excel") {
        write_excel_csv(x = data, "data.xlsx")
      }
      else {"copy"}
      data
    }))}

shinyApp(ui = ui, server = server)

3 posts were merged into an existing topic: not able to save the pivot table output as csv / excel from ShinyApp using rpivotTable

A post was merged into an existing topic: not able to save the pivot table output as csv / excel from ShinyApp using rpivotTable