r-将一个shapefile输入到Rshing并从中读取数据



我正在尝试制作一个闪亮的面板,用户可以在其中输入形状文件并提取其中的数据。代码似乎返回错误"无法打开数据源"。如有任何帮助,我们将不胜感激。

## Only run examples in interactive R sessions
if (interactive()) {

ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose shp File", accept = ".shp")
),
mainPanel(
tableOutput("contents")
)
)
)

server <- function(input, output) {
output$contents <- renderTable({
library(dplyr)
library(rgdal)
file <- input$file1
req(file)
x=readOGR(file$datapath) %>% .@data
})
}

shinyApp(ui, server)
}

对于闪亮的应用程序来说,单个.shp文件是不够的。YOu可以考虑用户fioreblombina在Rcommunity上发布的解决方案。

你可以在这里找到答案。

最新更新