upload shapefile in r shiny

I want to upload shapefile data, but I get a warning message "File not suitable with criteria" from the code that I made myself. below is the code that i made:

uploadShpfile = reactive ({
    if (!is.null(input$filemap)){
      shp <<- input$filemap
      print(shp)
      input_by_user = c()
      for (i in (1:length(input$filemap$datapath))) {
        temp <<- input$filemap$datapath[i]
        subb <- strsplit(temp, "[.]")
        
        input_by_user<-c(input_by_user,(subb[[1]][2]))
        print(input_by_user)
        
      }
      
      if(length(input_by_user[!duplicated(input_by_user)])==6 && length(input_by_user)==6){
        flag = 0
        for (i in 1:6){
          if((!input_by_user[i] %in% c("shp"))){
            flag = 1
            break
          }
        }
        if (flag ==1){
          is.validated$shp<-0
          showModal(modalDialog(
            title = "Warning",
            "Format document must shp",
            easyClose = TRUE
          ))
        }else {
          is.validated$shp<-1
          for(i in (1:length(input$filemap$datapath))){
            temp <<- input$filemap$datapath[i]
            sub= str_split(as.character(temp), "/", n=3)
            
            #file path
            sub1 = str_split(as.character(temp), paste("/", as.character(i-1), ".", sep = ""), n=3)
            map_path = sub1 [[1]][1]
            
            #file name
            map_name = sub[[1]][3]
            
            #new file name
            new_name <- gsub(as.character(i-1), "shapetemp", map_name)
            
            #new name
            new_direct = paste(rute_permission)
            
            #copy the file to the working directory
            file.copy(temp, new_direct)
            
            #rename file
            #original name
            map_name <- substr_right(map_name, 5)
            name_org <<- paste(rute_permission, map_name, sep = "/")
            #final name
            new_name
            new_name <- substr_right(new_name, 13)
            name_final <<- paste(rute_permission, new_name, sep = "/")
            
            file.rename(name_org, name_final)
            
          }
        }
      }else{
        is.validated$shp <- 0
        showModal(modalDialog(
          title = "Warning",
          "File not suitable with criteria",
          easyClose = TRUE
        ))
      }
      
    }
  })

I haven't run the code, but will it need to be a zipped shapefile to get the projection and data files that go with the .shp file? Most of the uploads for .shp files are for zip files. It looks like you just want the .shp in your code.

thankyou so much for the answer... for that error of mine, it's been solved. but do you know how to solve the error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented, :
Loop 0 is not valid: Edge 0 is degenerate (duplicate vertex)

Sorry, not sure. But maybe you could provide a reproducible example? Where does the error appear?

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.