2017-09-18 10 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 함수는 두 가지 주요 인수를 취합니다.

1) filename - 파일이 가져올 이름입니다 (시작 부분에서만 평가되므로 사용자 입력에 따라 변경되는 경우 반응식 안에 넣습니다).

2) content - 이미 임시 파일을 작성하고 있으므로 content 함수에서 file 인수를 제공해야합니다.

그렇지 않으면 (예에서와 같이) 콘텐츠 기능을 지정하지 않고 ShinyApp 내부에 두 번째 .docx를 만듭니다.

+0

기자 패키지별로 docx 파일에 리플렛 맵을 추가하는 방법을 알고 계십니까? –

+1

.docx는 HTML을 지원하지 않습니다. 이것은 완전히 사실이 아니지만 형식화 된 테이블보다 더 정교한 것으로 생각하는 것이 가장 좋습니다. 그래서 .docx 안에는 전단지 지원이 없습니다. 자유를 원한다면 rMarkdown으로 전환하십시오. – Christian