我想使用以下命令读取shape文件:readOGR(infile $ datapath,input $ text1),其中输入$ text1来自ui.R中定义的Shiny textInput。我怎么能这样做?
Minimal Code:
library(shiny)
library(caret)
library(sp)
library(rgdal)
library(raster)
library(rgeos)
library(ggplot2)
library(RStoolbox)
setwd("C:/Users/User1/MyTestData")
shinyApp(
ui = fluidPage(
navbarPage(
"Example",
tabPanel("Option1",
sidebarPanel(
textInput("testfile1", "Input Test File","test_file"),
verbatimTextOutput("value1")
)
)
)
),
server <- function (input, output, session){
# Load specified file
filedata1 <- reactive({
infile1 <- input$FileInput
if (is.null(infile1)) {
# No upload
return(NULL)
}
myfile <- readOGR(infile1$datapath, infile1$name) # <-this doesn't work??
#myfile <- readOGR(dirname(infile1$datapath), infile1$name)
})
错误讯息: .local(x,y,...)中的错误:无法从参数y
获取Extent对象答案 0 :(得分:1)
这是在textInput中输入名称(不包括“.shp”扩展名)时在“MyTestData”文件夹中绘制形状文件的最小示例:
library(shiny)
library(rgdal)
library(ggplot2)
library(sp)
shinyApp(
ui = fluidPage(
textInput("FileInput", "Input Test File"),
plotOutput("map")),
server <- function (input, output, session){
# Load specified file
filedata <- reactive({
infile <- input$FileInput
if (!is.null(infile) && infile!="")
readOGR("C:/Users/User1/MyTestData", infile)
})
output$map <- renderPlot({
data <- filedata();
if(!is.null(data))
plot(data)})
})