0

I am using the R package Shiny to develop my own web application.

I have a download button which permits me to export the data into a excel file. In the excel file, there are 4 sheets and in each of them there is a data frame.

For example, in sheet1 there is dataTab1, in sheet2 there is dataTab2, in sheet 3 there is dataTab3 and in sheet4 there is dataTab4.

For doing this, I am using the function downloadHeader() in shiny server.R.

Here is my code:

output$downloadTab <- downloadHandler(

  filename ="Tab.xls",
  content = function(file) {



    #db <- paste(tmpdir,file,sep="/")            
    channel <- odbcConnectExcel(xls.file = file,readOnly=FALSE)
    sqlSave(channel, tab1, tablename = "sheet1",rownames = F)
    sqlSave(channel,  tab2, tablename = "sheet2",rownames = F)
    sqlSave(channel, tab3, tablename = "sheet3",rownames = F)
    sqlSave(channel, tab4, tablename = "sheet4",rownames = F)
    odbcClose(channel)

    },
    contentType="application/xls" 

)

The code is working very well and when I click on the button "downloadTab" the table results are downloaded in one excel file. The problem is that this code is working on Windows server but it's not working on Linux server.

Do you know how to solve this problem? Do you know how to export an excel file in Linux server?

Mily
  • 331
  • 1
  • 3
  • 18
  • You might want to check http://stackoverflow.com/questions/3426523/odbcconnectexcel-function-from-rodbc-package-for-r-not-found-on-ubuntu. However, this could be archieved using some other packages. In my case I have a working shiny aplication in a linux (redhat) server that exports excel files using openxlsx. – leosz Jan 26 '16 at 08:43
  • Could you show me your downloadHandler() code please? – Mily Jan 26 '16 at 11:06

1 Answers1

2

The following code will let you download an empty excel file using the package openxlsx even in a linux Shiny server.

  output$downloadData <- downloadHandler(
      filename = "myFile.xlsx",
      content = function(file) {
          wb <- createWorkbook()
          # Do more stuff here
          saveWorkbook(wb, file, TRUE)
      }
  )
leosz
  • 721
  • 5
  • 13