title: R - download shapefile from a Shiny app
body: <p>I'm stumped as to how I could set up my shiny app with a download button for shapefiles.</p>
  
  <p>I've followed references here</p>
  
  <p><a href="https://groups.google.com/forum/#!topic/shiny-discuss/q3-2O6JDk74" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/shiny-discuss/q3-2O6JDk74</a></p>
  
  <p><a href="https://gist.github.com/RCura/b6b1759ddb8ab4035f30" rel="nofollow noreferrer">https://gist.github.com/RCura/b6b1759ddb8ab4035f30</a></p>
  
  <p><a href="https://stackoverflow.com/questions/29129681/create-zip-file-error-running-command-had-status-127">Create zip file: error running command &quot; &quot; had status 127</a></p>
  
  <p>This is what I've got:</p>
  
  <pre><code>ui &lt;- fluidPage(  
    sidebarLayout(
      sidebarPanel(
        textInput("downloadShp","Filename:",value="fbCrawlExport.zip"),
        downloadButton('fbCrawlExport.zip', 'DownloadSHP')
      )))
  
  
  server &lt;- function(input, output) {
    output$fbCrawlExport.zip &lt;- downloadHandler(
      filename = 'fbCrawlExport.zip',
      content = function(file) {
        if (length(Sys.glob("fbCrawl.*"))&gt;0){
          file.remove(Sys.glob("fbCrawl.*"))
        }
        proj4string(Fg_filt2) &lt;- CRS("+proj=longlat +datum=WGS84")
        writeOGR(Fg_filt2, dsn="fbCrawl.shp", layer="fbCrawl", driver="ESRI Shapefile")
        write.csv(as.data.frame(cbind(Fg_filt2@data, as.data.frame(Fg_filt2()@coords))), "fbCrawl.csv")
        zip(zipfile='fbCrawlExport.zip', files=Sys.glob("fbCrawl.*"))
        file.copy("fbCrawlExport.zip", file)
        if (length(Sys.glob("fbCrawl.*"))&gt;0){
          file.remove(Sys.glob("fbCrawl.*"))
        }
      }
    )
  </code></pre>
  
  <p>The only way I can move forward right now is to download a csv.</p>
  
  <pre><code>ui &lt;- fluidPage(  
    textInput("downloadData","Filename:",value="filename.csv"),
        downloadButton('downloadData','Save')
      )
  
  server &lt;- function(input, output) {
    output$downloadData &lt;- downloadHandler(
      filename = input$downloadData,
      content = function(file) {
        write.csv(Fg_filt2,file)
      }
    )
  }
  </code></pre>
  
  <p>Yet, I can easily create a shapefile outside of a shiny using</p>
  
  <pre><code>proj4string(myshp) &lt;- CRS("+proj=longlat +datum=WGS84")
  writeOGR(myshp, "C:/Data/ShinyApps", "myshp_wgs84", driver = "ESRI Shapefile")
  </code></pre>