Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
noamanemobidata opened this issue Aug 16, 2021 · 3 comments
Open

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

noamanemobidata opened this issue Aug 16, 2021 · 3 comments

Comments

@noamanemobidata
Copy link

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
Copy link
Author

id parameter did the job for me

@noamanemobidata
Copy link
Author

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

@dcooley
Copy link
Collaborator

dcooley commented Jan 16, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants