R Shiny downloadHandler() error while downloading Shapefiles using writeogr()

Viewed 322

I am new to R shiny and creating a Shiny application to convert CSV file to shapefile. While running my codes I am getting this error:

enter image description here

My codes:

runApp(list(
  ui = bootstrapPage(
      fileInput('inputdata', 'Input file',accept=c('.csv')),
      plotOutput("xyPlot"),
      downloadButton('downloadShp', 'DownloadSHP')
       ),
  server = function(input, output) {

  output$xyPlot <-  renderPlot({

  myXY<- input$inputdata
  if (is.null(myXY)) 
    return(NULL)       

  xyPoints<-read.table(myXY$datapath, sep=",", header=T)

  SHP <- SpatialPointsDataFrame(coords= cbind(xyPoints[,1:2]), data =  xyPoints)
  proj4string = CRS('+proj=longlat +datum=NAD83')

  plot(SHP)

  output$downloadShp <- downloadHandler(
    filename = 'fbCrawlExport.zip',
    content = function(file) {
      if (length(Sys.glob("fbCrawl.*"))>0){
        file.remove(Sys.glob("fbCrawl.*"))
      }
      writeOGR(SHP, dsn="fbCrawl.shp", layer="fbCrawl", driver="ESRI Shapefile")
      write.csv(as.data.frame(cbind(SHP@data, as.data.frame(SHP@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.*"))
      }
    }
  )

  }) 
 }
 ))
1 Answers
Related