【发布时间】:2022-01-21 02:30:52
【问题描述】:
我正在编写一个闪亮的应用程序:
- 创建一个 gt 表
- 将 gt 表保存为图像(临时文件)
- 使用 {officer} 包将该图像传递到 word 文档中
我在创建图像时遇到困难......任何帮助表示赞赏......这是我的代表
library(shiny)
library(gt)
library(dplyr)
ui <- fluidPage(
downloadButton("report", "Generate Report")
)
server <- function(input, output, session) {
my_table <- render_gt(
mtcars[1:5,1:5] %>%
gt()
)
my_image <-reactive({
outfile <- tempfile(fileext='.png')
gtsave(my_table, outfile, width = 400, height = 300)
})
output$report <- downloadHandler(
filename = function() {
"download.docx"
},
content = function(file) {
print(read_docx() %>%
body_add_img(my_image()),
target = file)
},
contentType = "docx"
)
}
shinyApp(ui, server)
【问题讨论】: