I have this shiny R server code that I am trying to work:
vertices <-
structure(list(lat = c(20.99, 20.99, 21.01, 21.01, 20.99), lng = c(83.99,
84.01, 84.01, 83.99, 83.99)), class = "data.frame", row.names = c(NA,
-5L))
server <- function(input, output, session) {
output$map <- renderGoogle_map({
google_map(key = apikey,
map_type = "satellite",
location = c(21.92, 85.43),
zoom = 14
) %>%
add_polygons(vertices,lat = "lat", lon = "lng",editable = T)
})
observeEvent(input$map_polygon_edited, {
edited_data <- input$map_polygon_edited
print(edited_data)
})
}
While I can see the google map and a rectangle with handles on the vertices that are draggable, I donot get the observer reactive input$map_polygon_edited working.
i have tried adding an id parameter in add_polygons() but am not sure how that would work as the googleway documentations says that the id has to be a column name. So what exactly do we pass as map_id in the observer event? The column name or the map output name or the row content?
The doc is not very clear but there's an example in the file manual_tests.R.
In fact, the
editableargument must be the name of aTRUE/FALSEcolumn of the data which indicates whether the polygon defined at each row is editable or not.So, firstly, your dataframe
verticesis not appropriate. You firstly have to construct a polyline which represents this polygon, with the help of the googlePolylines package. Then, make a one-row dataframe with this polyline in a column and with another column containingTRUEto indicate that the polygon represented by this polyline is editable:then:
I didn't test because I don't have an API key.