Hello,
I have installed the development version of leaflet so I can use some of the leaflet.draw plugin functionalities. My end goal is to allow a user of my Shiny app to draw a custom polygon on the leaflet map. From which, I can use the polygon coordinates to subset spatial data.
My specific question concerns the addDrawToolbar() function: How do I extract the coordinates of user created objects from the returned value of addDrawToolbar()?
I am using the following code in a shiny implementation and --as suggested in the function documentation-- am trying to extract the coordinates using input$drawnItems_create[[3]]$coordinates. Clearly, I'm not following the proper usage because I only get a NULL value returned. Here's my code:
devtools::install_github("byzheng/leaflet")
library(shiny)
library(leaflet)
shinyUI(bootstrapPage(
tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
leafletOutput("map", width = "100%", height = "100%"),
absolutePanel(top = 80, right = 10, width = 200,
actionButton("drawPoints", "Draw polygon")
)
))
shinyServer(function(input, output, session) {
output$map <- renderLeaflet({
addTiles(leaflet())
})
# User draws polygon
observeEvent(input$drawPoints, {
leafletProxy("map") %>%
addDrawToolbar()
print(input$drawnItems_create[[3]]$coordinates) # this returns NULL
})
})
Any suggestions or assistance would be appreciated. Thank you,
Matt Schumwinger
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/cc55a113-7b74-4dec-836f-7c0bd203f749%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/c911b713-c864-426a-b4b9-a2fdd4813441%40googlegroups.com.