0

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
Tj Laroue
  • 23
  • 7
  • 1
    Can you share the code that you used? You might want to read [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – epo3 Oct 04 '16 at 15:03
  • Caching problem? You could try to close the app, type `rm(list = ls())` and restart. – nilsole Oct 04 '16 at 15:05
  • Thanks for the help! I have added the code! – Tj Laroue Oct 04 '16 at 16:25

1 Answers1

0

I believe the error is that I didn't tell it to ever overwrite the old file that is there.

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', overwrite = TRUE)

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)
})
Tj Laroue
  • 23
  • 7