brushed points in leaflet

I am working on a map shinyapp using leaflet. In the normal maps, it was possible to get brushedPoints to get a table.
Is there any way to get brushedPoints() or similar functionality in leaflet?
If I hold shift and click and drag, it makes a box, but then zooms into that box. Can I disable the zoom and instead return the points?
Thanks!

You have the option to listen to any points clicked on the rendered map - but you will have to build any logic on top of that (storing the previous point clicked and drawing a rectangle / identifying and counting points within) yourself.

For an example of a map listening to points clicked consider this code (it is built by slightly modifying my example of Virginia counties that I had lying around; you can disregard any of that).

library(shiny)
library(leaflet)
library(sf)

# VA counties - downloaded via the awesome tigris package
shape <- tigris::counties(state = "VA", class = "sf")


# Define UI 
ui <- fluidPage(

    # Application title
    titlePanel("The Old Dominion"),

    # Top panel with county name
    verticalLayout(
        
        wellPanel(textOutput("cnty")),

        # the map itself
        mainPanel(
           leafletOutput("map")
        )
    )
)

# Define server logic       
server <- function(input, output) {
    
    output$map <- renderLeaflet({
        leaflet() %>% 
            addProviderTiles("Stamen.Toner") %>% 
            addPolygons(data = shape, 
                        fillColor = "aliceblue", 
                        color = "grey",
                        layerId = ~COUNTYNS)
    })
    
    # this is the fun part!
    observe({ 
        event <- input$map_click
        output$cnty <- renderText(paste("lng:", event$lng, "lat:", event$lat))

    })
}

# Run the application 
shinyApp(ui = ui, server = server)

Thanks.
I suppose one could then have a plus-minus of lat-long from that click point to get all datapoints within some range.

If I was writing it I would take the bounding box of the two points clicked, turn it into a polygon and run sf::st_join() with the points object.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.