Created
September 18, 2014 20:44
-
-
Save RCura/f3b3c7d224f1701a9d7f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require(shiny) | |
require(sp) | |
require(rgdal) | |
runApp( | |
list( | |
ui = bootstrapPage( | |
fileInput('inputdata', 'Input file',accept=c('.csv')), | |
plotOutput("xyPlot"), | |
downloadButton('downloadShp', 'DownloadSHP') | |
), | |
server = function(input, output) { | |
createShp <- reactive({ | |
myXY <- input$inputdata | |
if (is.null(myXY)){ | |
return(NULL) | |
} else { | |
xyPoints <- read.table(myXY$datapath, sep=",", header=T) | |
SHP <- SpatialPointsDataFrame(coords= cbind(xyPoints[,1:2]), data = xyPoints) | |
#proj4string(SHP) <- CRS('+proj=longlat +datum=NAD83') | |
return(SHP) | |
} | |
}) | |
output$xyPlot <- renderPlot({ | |
validate( | |
need(!is.null(input$inputdata), "Please select a data set") | |
) | |
plot(createShp()) | |
}) | |
output$downloadShp <- downloadHandler( | |
filename = 'shpExport.zip', | |
content = function(file) { | |
if (length(Sys.glob("shpExport.*"))>0){ | |
file.remove(Sys.glob("shpExport.*")) | |
} | |
writeOGR(createShp(), dsn="shpExport.shp", layer="shpExport", driver="ESRI Shapefile") | |
zip(zipfile='shpExport.zip', files=Sys.glob("shpExport.*")) | |
file.copy("shpExport.zip", file) | |
if (length(Sys.glob("shpExport.*"))>0){ | |
file.remove(Sys.glob("shpExport.*")) | |
} | |
} | |
) | |
}) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment