我是 Rshiny 的新手,在将 .docx 文件(由官员生成)转换为 .pdf 时遇到了麻烦。.docx 文件生成时没有任何错误,但我不确定如何使用 downloadhandler 下载相同 .docx 文档的 pdf 文件。下面是我用来首先将 .docx 转换为 .pdf 然后使用 downloadhandler 下载 pdf 文件的代码。请帮助我更正下载pdf文件的代码。
observeEvent(
input$GenerateProtcolDocument_individual,
{
reportname_individual <-
genReport_individual()#function to generate word document using officer package
doc_list_individual <- length(reportname_individual)
url_doc_individual <- list()
office_shot <-
function(wd = getwd(), file) {
# function to convert word docx to pdf
cmd_ <- sprintf("C:/Program Files/LibreOffice/program/soffice.exe",
wd,
file)
system(cmd_)
pdf_file <- gsub("\\.(docx|pptx)$", ".pdf", basename(file))
return (pdf_file)
}
my.file <- office_shot(file = reportname_individual)
for (i in 1:doc_list_individual) {
url_doc_individual[[i]] <-
a(reportname_individual[i],
href = paste(reportname_individual[i], sep = ""))
}
output$reportlinks_individual <-
renderUI({
#This works as required creates hyperlink of the documents
box(
p("Click the link to download individual document"),
br(),
url_doc_individual,
br(),
width = 12
)
})
output$Download_pdf <- downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".pdf", sep = "")
},
content = function(file) {
pdf(my.file, file) #my.file is the pdf file returned from **office_shot** function
dev.off()
}
)
})