googleway icon indicating copy to clipboard operation
googleway copied to clipboard

Add layer_id from a dataframe like "lat" and "lng"

Open noamanemobidata opened this issue 3 years ago • 3 comments

Hello!

is it possible to fill in the "layer_id" parameter of the function add_markers directly from a dataframe, just like "lat" and "lng" ?

I know that we can do it with a for loop, but I try to use it in a shiny app and avoid for loops.

library(shiny)
library(googleway)
library(dplyr)
map_key<- "***" 

ui <- fluidPage(


  sidebarLayout(
    sidebarPanel(

      actionButton(inputId = "addMarkers",label = "Add markers"), 
      verbatimTextOutput("clikedLayer")
      
      
    ),
    
    mainPanel(
      
      div(
        
        tags$style(type = "text/css", "#map {height: calc(100vh - 5px) !important;}"),
        google_mapOutput("map"))
    )
  )
)

server <- function(input, output, session) {
  
  
  
  df= data.frame(lat=c(45.1,45.2,45.3), lng=c(1.1,1.2,1.3), layer_id= c("id1","id2", "id3"))
  
  output$map <- renderGoogle_map({
    
    google_map(key = map_key,geolocation = T,
               
        
               location = c(47.6062442,2.1148086),
               zoom = 10)
    
    
    
  })
  
  
  
  observeEvent(input$addMarkers,{
    

    
    google_map_update(map_id = "map") %>%
      googleway::add_markers(data = df, lat = "lat", lon = "lng",
                             layer_id = "layer_id", 
                             update_map_view = T)
    
    
    output$clikedLayer<- renderPrint({
      req(input$map_marker_click)
      
      print(input$map_marker_click)
    })
    

})

}
shinyApp(ui = ui, server = server)


noamanemobidata avatar Aug 16 '21 10:08 noamanemobidata

id parameter did the job for me

noamanemobidata avatar Aug 17 '21 19:08 noamanemobidata

I reopen because id can't be used to remove the marker using the function clear_markers we need layer_id

noamanemobidata avatar Aug 18 '21 08:08 noamanemobidata

is it possible to fill in the "layer_id" parameter of the function add_markers directly from a dataframe, just like "lat" and "lng"?

The layer_id can only be a single string, so I don't see how it can be filled in directly from a dataframe?

dcooley avatar Jan 16 '22 21:01 dcooley