Skip to content

Instantly share code, notes, and snippets.

@RCura
Created March 16, 2014 18:28
Show Gist options
  • Select an option

  • Save RCura/9587685 to your computer and use it in GitHub Desktop.

Select an option

Save RCura/9587685 to your computer and use it in GitHub Desktop.
library(shiny)
require(maptools)
shinyServer(function(input, output) {
uploadShpfile <- reactive({
if (!is.null(input$shpFile)){
shpDF <- input$shpFile
prevWD <- getwd()
uploadDirectory <- dirname(shpDF$datapath[1])
setwd(uploadDirectory)
for (i in 1:nrow(shpDF)){
file.rename(shpDF$datapath[i], shpDF$name[i])
}
shpName <- shpDF$name[grep(x=shpDF$name, pattern="*.shp")]
shpPath <- paste(uploadDirectory, shpName, sep="/")
setwd(prevWD)
shpFile <- readShapePoly(shpPath)
return(shpFile)
} else {
return()
}
})
output$map <- renderPlot({
if (!is.null(uploadShpfile())){
plot(uploadShpfile())
}
})
})
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Shapefile plot"),
sidebarPanel(
fileInput(inputId="shpFile", label="Shp", multiple=TRUE)),
mainPanel(
plotOutput("map")
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment