Skip to content

Instantly share code, notes, and snippets.

@RCura
Created May 19, 2014 20:48
Show Gist options
  • Save RCura/b6b1759ddb8ab4035f30 to your computer and use it in GitHub Desktop.
Save RCura/b6b1759ddb8ab4035f30 to your computer and use it in GitHub Desktop.
Shp download
output$downloadShp <- downloadHandler(
filename = 'fbCrawlExport.zip',
content = function(file) {
if (length(Sys.glob("fbCrawl.*"))>0){
file.remove(Sys.glob("fbCrawl.*"))
}
writeOGR(getGeoContent(), dsn="fbCrawl.shp", layer="fbCrawl", driver="ESRI Shapefile")
write.csv(as.data.frame(cbind(getGeoContent()@data, as.data.frame(getGeoContent()@coords))), "fbCrawl.csv")
zip(zipfile='fbCrawlExport.zip', files=Sys.glob("fbCrawl.*"))
file.copy("fbCrawlExport.zip", file)
if (length(Sys.glob("fbCrawl.*"))>0){
file.remove(Sys.glob("fbCrawl.*"))
}
}
)
@lauren-oldham
Copy link

For anyone having issues getting this code to work (as I did!), try two things:

  1. Open the app in your browser. It won't download in the R environment.
  2. If you're getting an error with the zip function, check out this solution utilizing Rtools. Worked for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment