title: R shiny: printing the console output produced by an R package to UI
body: <p>I am using an R package that, in addition to calculating and returning things, prints some very useful info to the console. For example, it prints what iteration it is on right now.</p>
  
  <p>How could I print that console output directly to my UI?</p>
  
  <p>Assume this is my UI:</p>
  
  <pre><code>ui &lt;- shinyUI(
    fluidPage(
      titlePanel("Print consol output"),
      sidebarLayout(
        sidebarPanel(actionButton("go", "Go")),
        mainPanel(
          verbatimTextOutput("console_text")
        )
      )
    )
  )
  </code></pre>
  
  <p>My user clicks on actionButton “Go” and my package starts doing things - while sending stuff to the console at the same time. I guess, I want the content of the console to be saved as output$console_text - but I don’t know if that’s the right approach and how to do it.</p>
  
  <p>I didn't want to make the code super-complicated. So, instead of a package, I created my own little printing function in Server.</p>
  
  <pre><code>server &lt;- function(input, output, session) {
    myfunction &lt;- function(x) { 
       for(i in 1:x) cat(i)
       return(x)
    }
    observeEvent(input$go, {
      {
         # This is probably wrong:
        output$console_text &lt;- renderPrint(onerun &lt;- myfunction(20))
      }
    })
  }
  
  shinyApp(ui, server)
  </code></pre>
  
  <p>Thank you very much!</p>