我想创建一个函数来保存 downloadHandler 函数并动态提供它的详细信息,但我不断收到消息
“找不到模式‘函数’的对象‘plotFunction’”
我的下载功能如下:
downloadPlots <- function(fileName,plotFunction,fileFormat,fileContentType){
if(fileFormat=="pdf"){ #because it doesn't require specification of contentType. Others do
downloadHandler(
filename = fileName,
content = function(file) {
pdf(file, pointsize = 12, bg = "white", res = NA)
FUN <- match.fun(plotFunction)
FUN()
dev.off()
}
)
}else{
downloadHandler(
filename = fileName,
content = function(file) {
if(fileFormat=="png")
png(file, pointsize = 12, bg = "white", res = NA)
FUN <- match.fun(plotFunction,descend = TRUE)
FUN()
dev.off()
},
contentType = fileContentType
)
}
}
这就是函数的调用方式
output$histPng <- downloadPlots("histogram.png",histogram(),"png","image/png")
在ui.R中,下载plot的代码如下:
downloadButton('histPng','PNG')