1

How can I catch a circle click event with a googleway map in R Shiny?

Here is my code - based on the googleway vignette - however the observer doesn't fire.

library(tidyverse)
library(shiny)
library(googleway)

ui <- fluidPage(
  google_mapOutput(outputId = "map")
)

server <- function(input, output){

  map_key <- ''

  output$map <- renderGoogle_map({

    google_map(key = map_key) %>%
      add_circles(data = tram_stops, id = "stop_id", lat = "stop_lat", lon = "stop_lon"
                   )
  })

  observeEvent(input$map_circle_click, {
    cat(input$map_circle_click$id) # doesn't fire!
  })

}

shinyApp(ui, server)

Similar code with polygons works.

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
Vlad
  • 3,058
  • 4
  • 25
  • 53
  • I think there's no `click` event for the circles. There is only `circle_drag` and `circle_edit`. – Stéphane Laurent Aug 30 '18 at 15:21
  • 1
    Use `map_shape_click` - I think you've found an error in the vignette (and code). The specific click event is [called here](https://github.com/SymbolixAU/googleway/blob/master/inst/htmlwidgets/lib/circles/circles.js#L122) and [defined here](https://github.com/SymbolixAU/googleway/blob/master/inst/htmlwidgets/lib/map/map_events.js#L114) – SymbolixAU Aug 31 '18 at 00:11
  • Look at the tests here: https://github.com/SymbolixAU/googleway/blob/60f1b7198893d524d98c157837d73bb77a4faf18/tests/manual_tests.R#L580 – Stéphane Laurent Aug 31 '18 at 03:13
  • @StéphaneLaurent my apologies; you're correct. – SymbolixAU Aug 31 '18 at 04:25

1 Answers1

1

As per SymbolixAU comment

  observeEvent(input$map_shape_click, {
    cat(input$map_shape_click$id) # this works!
  })

I suspect this might change in a future version of googleway :)

Vlad
  • 3,058
  • 4
  • 25
  • 53