如何在Shiny中增加downloadHandler的内存大小

时间:2015-01-12 15:53:06

标签: r shiny

当运行Shiny时,我会在调用下载函数时收到“java.lang.OutOfMemoryError:Java堆空间”的消息。它适用于数据文件较小的情况;但是我正在查看的实例中所有表的组合应该少于5,000行和15列。有人可以帮助我使用这种文件大小使我的downloadHandler功能正常吗?

*# server.R*

library(XLConnect)

shinyServer(function(input, output, session) {

  ... (filtering operation on a data frame to create multiple sub tables)

  output$downloadData <- downloadHandler(

    filename = function() {paste(input$category,"_raw_token_data.xlsx")},

    content = function(file){
      fname <- paste(file,"xlsx",sep=".")
      wb <- loadWorkbook(fname, create = TRUE)
      createSheet(wb, name = "-terms")
      createSheet(wb, name = "+terms")
      createSheet(wb, name = "-tokens")
      createSheet(wb, name = "+tokens")
      createSheet(wb, name = "test_stats")
      writeWorksheet(wb, raw()$filter_neg, sheet = "-terms") 
      writeWorksheet(wb, raw()$filter_kw, sheet = "+terms") 
      writeWorksheet(wb, df()$neg_raw, sheet = "-tokens") 
      writeWorksheet(wb, df()$rel_raw, sheet = "+tokens") 
      writeWorksheet(wb, df()$test_raw, sheet = "test_stats") 
      saveWorkbook(wb)
      file.rename(fname,file)
    }

  ) # closing for downloadHandler

}) # closing for shinyServer

解决方案:

options(java.parameters = "-Xmx1g") # increase heap size to 1gb
library(RWeka)

0 个答案:

没有答案