googleway
googleway copied to clipboard
Add layer_id from a dataframe like "lat" and "lng"
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)
id
parameter did the job for me
I reopen because id
can't be used to remove the marker using the function clear_markers
we need layer_id
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?