2016-10-04 7 views
0

shinyappが動作していて、sharkappとやりとりした後にダウンロードできるrmarkdownドキュメントを含めたかったのです。Rが古い.Rmdファイルを参照している理由

.rmdファイルを作成し始めたので、私は変更と編集を行いましたが、まだ古いバージョンが保存されています。私はこれを知っている。なぜなら、.rmdファイルには表示されていないテキストが追加されていますが、ドキュメントの名前を1.rmdに変更し、Rコードで新しいドキュメントを生成するとします。

UI

   radioButtons('format', 'Document format', c('PDF', 'HTML', 'Word'), 
         inline = TRUE), 
      downloadButton('downloadReport', 'Download Report'), 

サーバー

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。

+1

使用したコードを共有できますか? [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)をお読みください。 – epo3

+0

キャッシングの問題?あなたはアプリを終了し、 'rm(list = ls()) 'と打ち込んで再起動することができます。 – nilsole

+0

助けてくれてありがとう!私はコードを追加しました! –

答えて

0

エラーは、そこにある古いファイルを上書きするようには言わなかったと思います。

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) 
}) 
関連する問題