【发布时间】:2018-08-02 09:58:55
【问题描述】:
当我下载报告时,它始终是 PDF 版本。我已经分别测试了每一个,它们都可以工作,所以问题出在开关上,但问题是我尝试了一些东西,但没有任何效果,我不明白为什么。
这是我的代码:
library(rmarkdown)
ui <- fluidPage(
selectInput("algo", "Selection de l'agorithme utilise pour la simulation:", choice = list("algo1", "algo2")),
radioButtons('format', 'Document format', c('PDF', 'HTML', 'Word'), inline = TRUE),
downloadButton("report", "Generate report")
)
server <- function(input, output, session) {
output$report <- downloadHandler(
filename = switch(input$format,
"Word" = function() {
paste("reportHtml-", Sys.Date(), ".docx", sep="")
},
"PDF" = function() {
paste("reportPDF-", Sys.Date(), ".pdf", sep="")
},
"Word" = function() {
paste("reportHtml-", Sys.Date(), ".html", sep="")
}
),
content = switch(input$format,
"Word" = function(file1) {
report <- file.path("C:/R_sources/test/reportWord.Rmd")
params <- list(n = input$algo)
rmarkdown::render(report, output_file = file1,
params = params,
envir = new.env(parent = globalenv())
)
},
"PDF" = function(file2) {
report <- file.path("C:/R_sources/test/reportPdf.Rmd")
params <- list(n = input$algo)
rmarkdown::render(report, output_file = file2,
params = params,
envir = new.env(parent = globalenv())
)
},
"Word" = function(file3) {
report <- file.path("C:/R_sources/test/reportWord.Rmd")
params <- list(n = input$algo)
rmarkdown::render(report, output_file = file3,
params = params,
envir = new.env(parent = globalenv())
)
}
)
)
}
shinyApp(ui, server)
【问题讨论】:
-
在代码中有两个“Word”大小写,但无论如何它都不起作用。
标签: r download shiny switch-statement