Using .zip function on R Shiny to download files from the app (on Mac)

I'm trying to create a .zip folder that can be downloaded using R shiny on a MAC computer. The app is working fine, and the zip() function works well when not in the app - but when the two are together the zip() function stops working, and I get the following error when I click on the download link in the app:

[1] "/var/folders/yt/1vghl8k96k73y8pfjnpkdzcsv87dy2/T//RtmpfHjfKp"
Warning: Error in if: argument is of length zero
  [No stack trace available]

Here is my code:

shinyApp(
  ui = navbarPage("Main Title", theme = shinytheme("flatly"),
                  tabPanel("First Tab", 
                           sidebarLayout(
                             sidebarPanel(
                               selectInput("sps",  
                                          ...
                                           ),      
                               radioButtons("mod",
                                            ...
                                            ),
                               
                               radioButtons("radioSelection",
                                            "rang",
                                            ...
                                            ),
                               sliderInput("year",                                   
                                           ...
                                           ), 
                               
                               downloadLink('downloadData1', 'Click here to download data',class = "butt"),
                               tags$head(tags$style(".butt{background-color:lightgray;} .butt{color: black;}"))
                               
                              )
                           )
                  )
  ),
  server = function(input, output, session) { 
    
    output$downloadData1 <- downloadHandler(
      filename = function() {
        name1 <- sub(" ","",input$sps)  
        if(input$mod == "X") {
          name_part <- "_local-estimator"} else {
            name_part <- "_spatially-smooth"
          }
        paste(input$year, name1,"_", input$rang, name_part, "_ArrivalDate.zip", sep="")
      },
      
      content = function(name1) {
        fs <- c()
        tmpdir <- tempdir()
        setwd(tempdir())
        print (tempdir())
        
        arrtab <- arr_csv(input$year, input$sps, input$mod, input$rang)
        write.csv(arrtab, file = "data.csv")
        write.table(read_me1, file = "read_me.txt", row.names = FALSE, col.names = FALSE)
        fs <- c("data.csv", "read_me.txt")
        print(fs)
        
        zip(
          zipfile=name1, files=Sys.glob(fs),
          recurse = TRUE,
          include_directories = TRUE,
          root = "."
        )
        
        if(file.exists(name1)) {file.rename(name1, name1)}
      },
      contentType = "application/zip"
    )
 }
)

I've already checked this solution (https://stackoverflow.com/questions/27067975/shiny-r-zip-multiple-pdfs-for-download) and couldn't make it work.

Thank you!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.