R使用writeogr()下载shapefile时发生downloadHandler()错误

R使用writeogr()下载shapefile时发生downloadHandler()错误,r,shiny,R,Shiny,我不熟悉R Shinny并创建一个Shinny应用程序来将CSV文件转换为shapefile。运行代码时,我遇到以下错误: 我的代码: runApp(list( ui = bootstrapPage( fileInput('inputdata', 'Input file',accept=c('.csv')), plotOutput("xyPlot"), downloadButton('downloadShp', 'DownloadSHP')

我不熟悉R Shinny并创建一个Shinny应用程序来将CSV文件转换为shapefile。运行代码时,我遇到以下错误:

我的代码:

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.*"))
      }
    }
  )

  }) 
 }
 ))
runApp(列表(
ui=引导(
fileInput('inputdata','Input file',accept=c('.csv'),
plotOutput(“xyPlot”),
downloadButton('downloadShp','downloadShp')
),
服务器=功能(输入、输出){

输出$xyPlot我使用Rtools解决了这个问题。 这是我的更新代码

require(shiny)
require(sp)
require(rgdal)
Sys.setenv("R_ZIPCMD" = "C:/Rtools/bin/zip.exe")

runApp(
  list(
ui = bootstrapPage(
  fileInput('inputdata', 'Input file',accept=c('.csv')),
  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("+init=epsg:4326")
      return(SHP)
    }
  })

  output$downloadShp <- downloadHandler(

    filename = function() { paste0("shpExport.zip") }, #paste('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.*"),zip = Sys.getenv("R_ZIPCMD", "zip"))
      file.copy("shpExport.zip", file)
      if (length(Sys.glob("shpExport.*"))>0){
        file.remove(Sys.glob("shpExport.*"))
      }
    }
  )

}) 
)
require(闪亮)
需要(sp)
需要(rgdal)
Sys.setenv(“R_ZIPCMD”=“C:/Rtools/bin/zip.exe”)
runApp(
名单(
ui=引导(
fileInput('inputdata','Input file',accept=c('.csv'),
downloadButton('downloadShp','downloadShp')
),
服务器=功能(输入、输出){

createShp能否提供一个示例数据文件?该文件与此类似,具有X和Y坐标。X Y 74.761725 34.6015025 74.763425 34.6014575 74.766075 34.6014425 74.764975 34.6014375 74.766725 34.6014075 74.765975 34.6013925 74.762425 34.6013875 74.766825 34.6013825 74.761575 34.6013675 74.763825 34.6013575 74.766625 34。6013525 74.764175 34.6013475 74.766925 34.6013475 74.760625 34.6013425 74.766225 34.6013375 74.765875 34.6013225 74.766225 34.6013075 74.765975 34.6013025 74.760875 34.6012625 74.761875 34.6012625 74.764725 34.6012575 74.767225 34.6012525很抱歉在评论部分找不到附加文件选项。请编辑我的评论。您的代码似乎有效我很好。你能提供
sessionInfo()