【发布时间】:2021-04-29 00:06:40
【问题描述】:
我正在制作一个闪亮的应用程序,允许用户使用 sf 包上传 shapefile。当我通过浏览窗口选择 .shp 文件时,我得到一个error。如何允许用户上传 shapefile,然后让st_read' or readOGR. 读取它,我不知道为什么 st_read 会转到 C:\Users\Ed\AppData...,因为这不是 shapefile 的位置。
library(shiny)
library(shinydahsboard)
library(sf)
用户界面
ui = navbarPage("Project Eddy", theme = shinytheme("sandstone"),
tabPanel("Location",
sidebarLayout(sidebarPanel(fileInput("shp", "Please choose a Shapefile",
multiple = F,
".shp")),
mainPanel(plotlyOutput(outputId = "Area")))))
服务器
server = function(input, output, session) {
myshp.df = reactive({
# input$shp will be NULL initially. After the user selects
# and uploads a file, head of that data file by default,
# or all rows if selected, will be shown.
req(input$shp)
df = st_read(dsn = input$shp$datapath,
quite = T)
if(input$disp == "head") {
return(head(df))
}
else {
return(df)
}
})
output$Area = renderPlotly({
req(myshp.df())
a = myshp.df
c = leaflet(a) %>%
addPolygons(stroke = FALSE, fillOpacity = 0.5, smoothFactor = 0.5) %>%
addProviderTiles('Esri.WorldImagery')
})
})
错误
Warning in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
GDAL Error 4: Unable to open C:\Users\Ed\AppData\Local\Temp\RtmpioUU3m\b0cd5b1eb5c4fe4219e6c114\0.shx or C:\Users\Ed\AppData\Local\Temp\RtmpioUU3m\b0cd5b1eb5c4fe4219e6c114\0.SHX. Set SHAPE_RESTORE_SHX config option to YES to restore or create it.
Warning: Error in : Cannot open "C:\Users\Ed\AppData\Local\Temp\RtmpioUU3m\b0cd5b1eb5c4fe4219e6c114\0.shp"; The source could be corrupt or not supported. See `st_drivers()` for a list of supported formats.
128:
【问题讨论】: