Skip to content

Instantly share code, notes, and snippets.

@Bustami
Forked from yihui/input.Rnw
Created February 5, 2016 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bustami/29ab998334f1fede00b5 to your computer and use it in GitHub Desktop.
Save Bustami/29ab998334f1fede00b5 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