xlsx icon indicating copy to clipboard operation
xlsx copied to clipboard

incompatibility with shiny (a web interface of R)

Open GoogleCodeExporter opened this issue 10 years ago • 3 comments

What steps will reproduce the problem?
1. wanted to use this functionality in Shiny. 
http://www.inside-r.org/packages/cran/shiny/docs/downloadHandler
2. if i use write.xlsx function in xlsx package, it will detect the file name 
and decide the extension
3. However, Shiny package will automatically assign a temporary file name (some 
random number & meaning less letters) as the temp file name. xlsx package 
cannot figure out what ext to use correctly.

What is the expected output? What do you see instead?
xlsx cannot decide what extension to use.

What version of the product are you using? On what operating system?
windows, shiny 0.9.1





Please provide any additional information below.
suggested modification: Modify write.xlsx function to be the following:

### start of code:

write.xlsx <- function(x, file, sheetName="Sheet1",
  col.names=TRUE, row.names=TRUE, append=FALSE, showNA=TRUE, forceext="") ##add additional parameter: forceext
{
  if (!is.data.frame(x))
    x <- data.frame(x)    # just because the error message is too ugly

  iOffset <- jOffset <- 0
  if (col.names)
    iOffset <- 1
  if (row.names)
    jOffset <- 1

  if (append && file.exists(file)){
    wb <- loadWorkbook(file)
  } else {
    if(forceext!=""){## if provided forceext, use that one. if not, determine extension by filename.
        ext <- forceext
    } else {
    ext <- gsub(".*\\.(.*)$", "\\1", basename(file))
    }
    wb  <- createWorkbook(type=ext)
  }  
  sheet <- createSheet(wb, sheetName)

### omitted more codes...


Original issue reported on code.google.com by [email protected] on 21 Apr 2014 at 10:49

GoogleCodeExporter avatar Jul 19 '15 20:07 GoogleCodeExporter

Hi Adrian, 

it takes time to set up your Shiny environment so i did not provide a good 
example here. However, i think the issue is quite straight forward; you can 
directly look at my suggested change and you should get what my problem is..

Thank you very much!

Best,
Ricky

Original comment by [email protected] on 21 Apr 2014 at 10:53

GoogleCodeExporter avatar Jul 19 '15 20:07 GoogleCodeExporter

The problem is with the loadWorkbook function.  Send an example of a filename 
that gets generated so I understand better.  Does it have an extension or not?  

Adrian

Original comment by [email protected] on 26 May 2014 at 12:24

GoogleCodeExporter avatar Jul 19 '15 20:07 GoogleCodeExporter

File does not have an extension, but user would like to force the behavior. Not sure whether a "forced extension" is the cleaner approach here, or if filetype should be determined somehow. I think filetype makes a better parameter name, but perhaps ideally it could be determined from the structure of the file.

colearendt avatar Jun 21 '17 06:06 colearendt