Open MitchStares opened 2 years ago
Added functionality inside leaflet.extras to allow for click events to register on drawn items in shiny. Switched Shiny app to using MitchStares/leaflet.extras.updated. https://github.com/MitchStares/leaflet.extras.updated/commit/16ba84f6dac8bcc9b0eba41f01228095b09058f0
App now stores drawn and uploaded polygons in data.frame (polygonTracker) for intelligent filtering on makeGrid. makeGrid()
and selectPlots()
function work within an observeEvent()
triggered by button press.
Primary issue for the implementation was determining what layer of leaflet the click belonged to. Uploaded shapefiles, even if stored on the same layer in leafletProxy() %>% addPolygon(group = "draw")
had a different data structure.
Uploaded files did not have an ID by default, and added IDs were stored under a separate layer within clickData$clickedPolygon$id$id[[1]]
(in my case, id$iter[[1]]).
Drawn shapefiles always stored id directly under clickData$clickedPolygon$id
.
Original implementation was using which()
to subset rows of polygonTracker using a long form OR statement ||
. This caused a weird error where multiple clicks on the map would trigger an atomic vector error on the which statement. Not entirely sure why.
Work around was to use an if() statement to determine if the names()
of a clickData$clickedPolygon$id contained "iter", instead of the logical OR statement on polygonTracker.
Solved in commit eac22e69be64531f1275e926f0b5ff9297b02202
Checkboxes to toggle the rendering of grids or plots implemented. UI done via checkboxGroupInput()
and server done with if() statements for each of the two options using %in% for the text values for each checkbox.
Grab centroids and display as pointsCreate polygons on random points in that list within polygon that meet size specifications