Generate PDF report with Shiny-server

2,141 views
Skip to first unread message

Huidong TIAN

unread,
Oct 15, 2013, 5:11:20 AM10/15/13
to shiny-...@googlegroups.com
The "showcase" of Rstudio-shiny gave a great case of generating PDF report with shiny-server. Anybody can explain how it works, or give the source code of it?

Robin Cura

unread,
Oct 15, 2013, 5:40:31 AM10/15/13
to Huidong TIAN, shiny-...@googlegroups.com
Hi,

It's probably created using knitr, here's an example of this :

ui.R :
downloadButton("downloadPDF", "Download the PDF report")

server.R :

output$downloadPDF <- downloadHandler(filename = "your_report.pdf",
                        content = function(file){
                            # generate PDF
                            knit2pdf("report.Rnw")
                           
                            # copy pdf to 'file'
                            file.copy("your_report.pdf", file)
                           
                            # delete generated files
                            file.remove("your_report.pdf", "your_report.tex",
                                        "your_report.aux", "your_report.log")
                           
                            # delete folder with plots
                            unlink("figure", recursive = TRUE)
                        },
                        contentType = "application/pdf"
        )

report.Rnw :

\begin{document}
\title{Custom report}
\maketitle
<<Example chunk, cache=FALSE, warning=FALSE, echo=FALSE, eval=TRUE, message=FALSE, prompt=FALSE, out.width='\\linewidth', out.height='\\textheight', fig.width=7, fig.height=4.95>>=
    plot(cars)
@
\end{document}


2013/10/15 Huidong TIAN <tienh...@gmail.com>
The "showcase" of Rstudio-shiny gave a great case of generating PDF report with shiny-server. Anybody can explain how it works, or give the source code of it?

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--

Huidong TIAN

unread,
Oct 15, 2013, 6:47:57 AM10/15/13
to shiny-...@googlegroups.com, Huidong TIAN
Thanks a lot!

I have also searched some codes like those you posted. However, the application in "showcase" looks much flexible and elegant. 

I will post my solution here when I found one.

Regard!
Reply all
Reply to author
Forward
0 new messages