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]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to