r - 允许用户以闪亮的方式上传 shapefile
问题描述
我正在制作一个闪亮的应用程序,允许用户使用sf
包上传 shapefile。当我通过浏览窗口选择 .shp 文件时,我得到一个 .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:
解决方案
ESRI shapefile 是众所周知的麻烦制造者,因为它们存在于多个文件中 - 单个*.shp
文件不足以让您的闪亮应用程序使用。
考虑用户 fiorepalombina 在 RStudio 社区论坛上提出的解决方案:https ://community.rstudio.com/t/shinyfiles-and-shapefiles/89099
推荐阅读
- entity-framework - EF Core 3.1 Linq 查询失败 - 无法将“System.Int32”类型的对象转换为“System.Boolean”类型
- c++ - 解释这个排序算法是如何工作的?
- c++ - tensorflow 错误 此文件需要 ISO C++ 2011 标准的编译器和库支持
- python - ImportError: 无法从 'apps.models' 导入名称 'modelname' (D:\project\django\projects\django\apps\models.py)
- sql - 导入多行文本文件
- if-statement - 如何在 Google 表格中查询返回值但将过滤后的值保留为空白的内容
- c++ - 为什么在多向量模板中调用分量向量的构造函数?
- javascript - 一次打开多个页面的 chrome 书签栏上的链接
- tensorflow - TF 2.0 TensorBoard 2.0.2 ValueError:名称投影仪的重复插件
- c - 为什么全局指针从函数返回后会改变它的值?