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
))
}
}
})