downloadHandler 関数を保持し、その詳細を動的にフィードする関数を作成したいのですが、メッセージを受け取り続けます
「モード 'function' のオブジェクト '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 では、プロットをダウンロードするためのコードは次のとおりです。
downloadButton('histPng','PNG')