4

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')
4

1 に答える 1

4

downloadPlots()問題 (テストなし) は、プロット関数を間違って渡している可能性があると思います。関数呼び出しからかっこを削除しhistogramます。

output$histPng <- downloadPlots("histogram.png",histogram,"png","image/png")
于 2013-06-07T08:44:05.313 に答える