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.*")) | |
} | |
} | |
) |
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
Hi guys
![capture](https://cloud.githubusercontent.com/assets/28763189/26168342/5d7ba736-3b57-11e7-927a-006474b366b1.PNG)
I am new to shiny App and have created a tool to convert csv to shapefile. I am using same code under downloadhandler but I am getting below error
Could you please guide me?
Thanks in adavance