Skip to content
Prev 28967 / 29559 Next

A leaflet question

Hi Erin,

I think it has to do with the naming convention.  If your map object is
called "plot", then you should expect the input to have the name
"plot_click" which you can access with `input$plot_click` You have looked
for input$plot_marker_click which hasn't been defined.

I'm not sure why nearPoints() throws an error in this case.


```
library(tigris)
library(leaflet)
library(sf)
options(tigris_use_cache = TRUE)
#Getting the data
tarrant <- tracts(state="TX",county="Tarrant",cb=TRUE)
tarrant_sp <- as(tarrant,"Spatial")

#Set up ui
ui <- fluidPage(
  leafletOutput("plot"),
  tableOutput("data")
)
#Set up server
server <- function(input, output, session) {
  #Draw map
  output$plot <- renderLeaflet({
    leaflet(tarrant_sp) %>% addTiles() %>%
      addPolygons(label=~TRACTCE)
  })
  #allegedly grab market clicks
  output$data <- renderTable({
    click <- input$plot_click
    cat("click class = ", class(click), "\n")
    cat(str(click), "\n")
    print(nearPoints(tarrant_sp, click))
  })
}
shinyApp(ui,server)
```

On Wed, Jun 1, 2022 at 10:15 AM Erin Hodgess <erinm.hodgess at gmail.com>
wrote: