我正在开发一个shiny 的应用程序,用户在其中上传一个文件,然后对其进行处理,生成一份报告,用户可以将其作为可编辑的单词下载.doctor .
除此之外,它还能按预期工作,尽管出现了一个"另存为"对话框窗口,似乎允许您 Select 目标目录,结果是.文档文件最终被保存到一个临时目录中,并带有一个随机生成的名称(这是在Windows下).
我怀疑这是由于使用了tempdir命令,这是使用rmarkdown生成下载文件的一部分.
应如何修改以下代码以允许 Select 目标文件夹?
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(knitr)
# Define UI for application that draws a histogram
ui <- fluidPage(
uiOutput('markdown'),
# Application title
titlePanel("Apptitle"),
# Sidebar with file input
sidebarLayout(
sidebarPanel(
fileInput(
inputId = "file1",
label = "Select file(s)",
multiple = TRUE,
accept = NULL,
width = NULL,
buttonLabel = "Browse...",
placeholder = "No file(s) selected"
),
downloadButton("report", "Generate report")
),
)
)
server <- function(input, output) {
output$report <- downloadHandler(
reactive(file <- input$file1),
filename = "wordreport.doc",
content = function(file) {
tempReport <- file.path(tempdir(), "wordreport.Rmd")
file.copy("wordreport.Rmd", tempReport, overwrite = TRUE)
params <- list(report.data = input$file1)
rmarkdown::render(tempReport, output_file = "wordreport.doc",
params = params,
envir = new.env(parent = globalenv()))
})
}
shinyApp(ui = ui, server = server)
谢谢你的帮助!
编辑:已修复,使用下面的解决方案,此处建议的代码编辑:Passing a dataframe as a parameter from Shiny app to RMarkdown