Skip to content

Instantly share code, notes, and snippets.

@vfulco
Forked from yihui/input.Rnw
Created February 8, 2017 23:29
Show Gist options
  • Save vfulco/892479c0acb6203aef4a69b565c1062e to your computer and use it in GitHub Desktop.
Save vfulco/892479c0acb6203aef4a69b565c1062e to your computer and use it in GitHub Desktop.
use knitr (knit2pdf) to generate a PDF report in a Shiny app

To see this app in action, run this in R:

library(shiny)
runGist('https://gist.github.com/yihui/6091942')
\documentclass{article}
\begin{document}
<<names>>=
input$firstname
input$lastname
@
\end{document}
library(knitr)
shinyServer(function(input, output) {
output$report = downloadHandler(
filename = 'myreport.pdf',
content = function(file) {
out = knit2pdf('input.Rnw', clean = TRUE)
file.rename(out, file) # move pdf to file for downloading
},
contentType = 'application/pdf'
)
})
library(shiny)
shinyUI(basicPage(
textInput('firstname', 'First name', value = 'Jimmy'),
textInput('lastname', 'Last name', value = 'John'),
downloadButton('report')
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment