Autoplot can not work in shiny PDF download

shiny

#1

why screeplot(prcomp(iris[,1:4])) can work, but autoplot(prcomp(iris[,1:4])) can not work ??
I really really need HELP!!

library(shiny)
library(shinydashboard)
library(ggplot2)
library(ggfortify)

ui=fluidPage(
  downloadButton("downloadp2",
                 label="Download PDF file")
)

server=function(input,output){
  output$downloadp2 <- downloadHandler(
    filename = function() {"PCA.pdf"},
    content = function(file) {
      pdf(file)
      autoplot(prcomp(iris[,1:4]))   
      # screeplot(prcomp(iris[,1:4]))
      dev.off()
    }
  )
}

shinyApp(ui=ui,server=server)

#2

You must print() the value that’s returned from autoplot. Normally you don’t have to do this when working at the R console, because top-level expressions are automatically printed. But when you’re inside of a function like this, you sometimes have to explicitly print().

See http://ggplot2.tidyverse.org/reference/print.ggplot.html


#3

Thank you.
The problem is solved, and Merry Xmas.