awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
364 stars 79 forks source link

Random error renaming xlsx file #453

Open NJeanray opened 5 years ago

NJeanray commented 5 years ago

Hi everyone,

I deployed my app on Shiny server and the following error happens quite randomly. In some cases, there is no issue at all, and sometimes it happens when I try to generate a xlsx file.

Here is the code which generated the xlsx file :

output$downloadData <- downloadHandler( filename = function(){ paste("CA_",CA.date(),"_",Sys.Date(),".xlsx",sep="") }, content = function(file){ fname <- paste(file,"xlsx",sep=".") validation_str <- data.frame(c('VALIDE','NON VALIDE'), stringsAsFactors=FALSE) list_vars <- c("tab.yyyyys.ET.statut.vide()","tasks.ET.activite.no.service()","In.UUU.No.XXXXX.react()","In.XXXXX.No.UUU.react()","Date.Signature.Checks.react()","Taches.Duree.NA.Checks.react()","Two.DE.Checks.react()","Yyyyy.Taches.Inactives.Checks()","Taux.calcules.NA.Checks.react()","doneRatio.restitution.EUR()","Tx.AVT.validation.DE()","Ecart.commentaires.DE()","CA.All.Studies.EUR.react()","Yyyyy.par.contrat.abcabc()","Yyyyys.Statut.RAP.react()","Yyyyys.Statut.TER.react()","validation_str") wb <- createWorkbook(fname)

 for (var in list_vars) {
        tab <- eval(parse(text = var))
        addWorksheet(wb, sheetName = var)
        if (var == 'Tx.AVT.validation.DE' | var == 'Ecart.commentaires.DE') {
          hs1 <- createStyle(halign = "CENTER")
          writeDataTable(wb, x =tab, sheet = var, headerStyle = hs1)
          setColWidths(wb, sheet = var, cols = 1:ncol(tab), widths = "auto") 
         }
        else {
          writeDataTable(wb, x =tab, sheet = var, headerStyle = createStyle())
          setColWidths(wb, sheet = var, cols = 1:ncol(tab), widths = "auto")   
    }
  }
  dataValidation(wb, "Tx.AVT.validation.DE()", cols = 14:15, rows=2:nrow(Tx.AVT.validation.DE()), type="list", value = "validation_str!$A$2:$A$3", allowBlank = FALSE)

  #print(Yyyyy.par.contrat.abcabc.CA.EUR.L.2018())
  insertPlot(wb, "Yyyyy.par.contrat.abcabc()", width = 12, height = 8, xy = NULL, startRow = nrow(Yyyyy.par.contrat.abcabc()) + 6,
             startCol = 1, fileType = "png", units = "in", dpi = 300)

  #print(Yyyyy.par.contrat.abcabc.CA.EUR.L.2019())
  insertPlot(wb, "Yyyyy.par.contrat.abcabc()", width = 12, height = 8, xy = NULL, startRow = nrow(Yyyyy.par.contrat.abcabc()) + 6,
             startCol = 20, fileType = "png", units = "in", dpi = 300)

  saveWorkbook(wb,file,overwrite = TRUE )
  file.rename(fname,file)
}  )

Expected Behavior

Downloading new Workbook in xlsx format.

Actual Behavior

Warning in file.rename(fname, file) : cannot rename file '/tmp/RtmpGV46Re/file13a6213e65abf.xlsx.xlsx' to '/tmp/RtmpGV46Re/file13a6213e65abf.xlsx', reason 'No such file or directory'

And the interface appears like this (seems that CSS/Js has been totally removed) :

image

Steps to Reproduce the Problem

There is no step to reproduce as this error happens randomly (15 downloads without any issue and then it crashes. Wait a few time, and it works again).

sessionInfo()

R version 3.5.1 (2018-07-02) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.1 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] compiler_3.5.1