title: Adding a download button to shiny, which prints the output of the server function
body: <p>Im having trouble adding a download button to download my plots, getting the error message: "eading objects from shinyoutput object not allowed."</p>
  
  <pre><code>´  x &lt;- output$Plot
    output$down &lt;- downloadHandler(
      filename = function(){
        paste("AAA", input$var3, sep = ".")
      },
      content = function(file){
        if(input$var3 == "png")
        png(file)
        else
          pdf(file)
        plot(x)
        dev.off
      }
    )´
  </code></pre>
  
  <p>The Problem is i cannot simply add plot(x(), y()) because in my server i do calculate around 7 different plots, each having a different dataset, and being "glued" together with else if. </p>
  
  <pre><code>`ui &lt;- fluidPage(
    sidebarLayout(
      sidebarPanel(
        selectInput("Select2","Partei:", choices = c("AFD", "CDU", "DieLinke", "FDP", "Gruene", "Piraten", "SPD", "total")),
        selectInput("Select1", "Function:", choices = c("Absolute Worthaufigkeiten", "Relative Worthaufigkeiten",
                                                        "Wordclouds", "Term frequencies", "Sentiment Analysis 1", "Importance")),
        radioButtons(inputId = "var3", label = "Select file type", choices = list("png", "pdf"))
      ),
      mainPanel(
      plotOutput("Plot"),
      downloadButton(outputId = "down", label = "Download the Plot")
    )))`
  
  
  `server &lt;- function(input, output) {output$Plot &lt;- renderPlot({
  if(input$Select1 == "Absolute Worthaufigkeiten"){
    if(input$Select2 == "AFD"){
      AAA %&gt;%
        filter(AFD &gt; 2) %&gt;%
        ggplot(aes(word, AFD, Jahr)) +
        geom_col(colour = "white", fill = "red2")
    }
    else{
      if(input$Select2 == "CDU"){
        AAA %&gt;%
          filter(CDU &gt; 80) %&gt;%
          ggplot(aes(word, CDU)) +
          geom_col(colour = "red3", fill = "red3") 
          else {
  
              }
             else {
            if(input$Select1 == "Importance"){
              if(input$Select2 == "AFD"){
                print("NA")
              else{
                if(input$Select2 == "CDU"){
  
                  book_words_CDU &lt;- tidy_CDU_total %&gt;%
                    count(book, word, sort = TRUE) %&gt;%
                    ungroup()
  
                  total_words_CDU&lt;- book_words_CDU %&gt;%
                    group_by(book) %&gt;% 
                    summarize(total = sum(n))
  
                  book_words_CDU &lt;- left_join(book_words_CDU, total_words_CDU)
  
                  book_words_CDU &lt;- book_words_CDU %&gt;%
                    bind_tf_idf(word, book, n) }})}
  </code></pre>
  
  <p>Is there any way to have shiny print out the output? </p>