[R] Mapedit::selectMap in shiny map.

nevil amos nevil.amos at gmail.com
Fri Feb 23 07:00:04 CET 2018


I would like to select polygons from an existing spatial polygon data set
interactively in a shiny leaflet map.
The process is straightforward in leaflet/ mapedit, however I need to
include the procedure in a shiny app map interface. I cannot work out how
to incorporate the selectMap() in the shiny app. An error is returned:

Here is some toy code showing the code in using leaflet locally:

library(mapedit)
library(leaflet)
options(stringsAsFactors = F)
bounds <- c(5.956063, 10.49511, 45.81706, 47.80848 )

lf <- leaflet() %>%
addTiles()%>%
addPolygons(data =gadmCHE,
label = ~NAME_1,
layerId = ~NAME_1)

selected <-selectMap(lf)

##the above works fine and returns a dataframe giving the ids of the
selected polygons.

##however the code below - trying to implement in shiny fails with "Can’t
call runApp() from within runApp(). If your application code contains
runApp(), please remove it.

library(shiny)
library(leaflet)
library(mapedit)

ui <- fluidPage(
leafletOutput(“mymap”)
)

server <- function(input, output, session) {

lf<-leaflet() %>%
addTiles()%>%
addPolygons(data =gadmCHE,
label = ~NAME_1,
layerId = ~NAME_1)
output$mymap <- renderLeaflet({selectMap(lf)
})
}
shinyApp(ui, server)

##How do I achieve the same in a shiny map?

	[[alternative HTML version deleted]]



More information about the R-help mailing list