I have a shinyapp that works and wanted to include an rmarkdown document that can be downloaded once you have interacted with my shinyapp.
As I started building the .rmd file I have made changes and edits to it but it is still has the old version saved. I know this because I added text to the .rmd file that isn't showing up but if i change the name of the document to 1.rmd and reference that in my R code it generates the new document.
ui
radioButtons('format', 'Document format', c('PDF', 'HTML', 'Word'),
inline = TRUE),
downloadButton('downloadReport', 'Download Report'),
server
output$downloadReport <- downloadHandler(
filename = function() {
paste('report', sep = '.', switch(
input$format, PDF = 'pdf', HTML = 'html', Word = 'docx'
))
},
content = function(file) {
src <- normalizePath('shinyAppTest1.Rmd')
# temporarily switch to the temp dir, in case you do not have write
# permission to the current working directory
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(src, 'shinyAppTest1.Rmd')
out <- rmarkdown::render('shinyAppTest1.Rmd', switch(
input$format,
PDF = pdf_document(fig_caption = TRUE, fig_width = 7, fig_height = 3.5),
HTML = html_document(),
Word = word_document()
))
file.rename(out, file)
}
)
rmd.
---
title: "Untitled"
output: pdf_document
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
You can also embed plots, for example:
TEST