2017-09-18 5 views
1

RstudioにThis exampleを再現しようとしましたが、うまくいきました。それから私はちょうど光ってテンプレートをダウンロードするためにすべてを一緒に置く!私は、サーバーのコンテンツを実行する場合、光沢を入れずに、それは私のテンプレートを更新してしまうレポーターパッケージからdocxレポートを光沢からダウンロード

library(shiny) 
library(ReporteRs) 
library(ReporteRsjars) 
library(ggplot2) 
library(magrittr) 
library(ggplot2) 
library(magrittr) 

ui<- fluidPage( 

    downloadButton('downloadData', 'Download') 

) 
server<- function(input, output,session) { 

    output$downloadData <- downloadHandler(
    filename = "file.docx", 

    content = function(file) { 

     target_file <- "bookmark_example.docx" # file to produce 
     template <- system.file(package = "ReporteRs", 
           "templates/bookmark_example.docx") # template example 

     doc = docx(template=template) 

     ft <- vanilla.table(data = head(iris), add.rownames=TRUE) 

     myplot1 <- ggplot(data = iris, aes(Sepal.Length, Petal.Length, color = Species), 
         alpha = I(0.7)) 


     doc %>% 
     addParagraph(value = "Jane Doe", stylename = "small", bookmark = "AUTHOR") %>% 
     addParagraph(value = "John Doe", stylename = "small", bookmark = "REVIEWER") %>% 
     addFlexTable(flextable = ft, bookmark = "DATA") %>% 
     addPlot(fun = print, x = myplot1, bookmark = "PLOT") %>% 
     writeDoc(file = target_file) 

    } 
) 
} 

shinyApp(ui=ui,server=server) 

を私はダウンロードボタンをクリックすると光沢で、それが返されます:それは動作しません

enter image description here

どのようなアイデアが間違いですか?

答えて

2

この行を確認してくださいと適応:

writeDoc(file = file) #replace target_file with file 

なぜ?関数DownloadHandlerは、次の2つの主な引数をとります。

1)ファイル名 - ファイル名は最初に評価されるので、ユーザー入力によって変更された場合は反応式の中に入れます。

2)content - すでにあなたのために一時ファイルを作成しているので、content関数からfile引数を指定する必要があります。

そうでなければ(例のように)、コンテンツ関数を指すことなくShinyAppのどこかに2番目の.docxを作成します。

+0

リポジトリパッケージによってdocxファイルにリーフレットマップを追加するにはどうすればよいですか? –

+1

.docxはHTMLをサポートしていませんが、これは完全には真実ではありませんが、フォーマット済みのテーブルより洗練されたものになると考えてください。だから、.docxの内部にリーフレットはサポートされていません。もっと自由が必要な場合は、rMarkdownに切り替えてください。 – Christian

関連する問題