Created
May 19, 2014 20:48
-
-
Save RCura/b6b1759ddb8ab4035f30 to your computer and use it in GitHub Desktop.
Shp download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.*")) | |
} | |
} | |
) |
Indeed, many many thanks!
For anyone having issues getting this code to work (as I did!), try two things:
- Open the app in your browser. It won't download in the R environment.
- 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
Thanks for sharing this, super helpful!