I want to create a function for that holds the downloadHandler function and feeds it its details dynamically but I keep getting the message
我想为它创建一个包含downloadHandler函数的函数并动态地向它提供它的细节,但是我一直在获取消息
"object 'plotFunction' of mode 'function' was not found"
未找到模式'function'的对象'plotFunction'
My function for downloading is as follows:
我的下载功能如下:
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
)
}
}
}
This is how the function is called
这就是函数的调用方式。
output$histPng <- downloadPlots("histogram.png",histogram(),"png","image/png")
In the ui.R, the code for downloading the plot is as follows:
在ui中。R,下载该地块的代码如下:
downloadButton('histPng','PNG')
1 个解决方案
#1
3
I think the problem (without any testing) may be that you are passing your plot function to downloadPlots()
incorrectly. Remove the parentheses from histogram
in your function call:
我认为问题(没有任何测试)可能是您不正确地将情节函数传递给downloadplot()。从函数调用的直方图中删除圆括号:
output$histPng <- downloadPlots("histogram.png",histogram,"png","image/png")
#1
3
I think the problem (without any testing) may be that you are passing your plot function to downloadPlots()
incorrectly. Remove the parentheses from histogram
in your function call:
我认为问题(没有任何测试)可能是您不正确地将情节函数传递给downloadplot()。从函数调用的直方图中删除圆括号:
output$histPng <- downloadPlots("histogram.png",histogram,"png","image/png")