我想创建一个函数来保存downloadHandler函数并动态地提供它的详细信息,但我不断收到消息
“找不到''''''''''''''''''''''''''''''''''''''
我的下载功能如下:
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中,下载图的代码如下:
downloadButton('histPng','PNG')
答案 0 :(得分:3)
我认为问题(没有任何测试)可能是您将绘图函数错误地传递给downloadPlots()
。从函数调用中的histogram
中删除括号:
output$histPng <- downloadPlots("histogram.png",histogram,"png","image/png")