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

137 views
Skip to first unread message

sid

unread,
Oct 31, 2018, 10:22:23 AM10/31/18
to Shiny - Web Framework for R
Hi guys,
I'm using rpivotTables Shinyapp to export the pivottable data as csv, excel, pdf using buttons (I don't want to export the actual data). However i'm unable to do so, can't figure out the reason due to my limited knowledge. I'm pasting my codes as well. I shall be really thankful for the help :slight_smile:
Kind regards



...
library(rpivotTable)
library(dplyr)
library(readr)
library(shiny)
library(openxlsx)

#ui
ui = fluidPage(
  radioButtons(inputId="format", label="Enter the format to download", 
               choices=c("none", "csv", "excel", "pdf", "copy"), inline = FALSE, selected="none"),


  fluidRow( rpivotTableOutput("pivot")))


#server
server = function(input, output, session) { 

  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$format =="csv") {
        write_csv( data, 'data.csv')
        
      } 
      if (input$format=="excel") {
        write.xlsx(data, "data.xlsx")
      } 
     
      data
     
    }))

}

shinyApp(ui = ui, server = server)


Omar Giorgetti

unread,
Apr 19, 2019, 10:40:33 AM4/19/19
to Shiny - Web Framework for R
Reply all
Reply to author
Forward
0 new messages