0
votes

I am using leaflet library in R Shiny. I want to add a new marker on the map with a mouse click. I am able to fetch latitude and longitude using input$mapid_click option. But I am not able to update the map in shiny app with a new marker.

1

1 Answers

1
votes

You can add them using the leafletProxy function.

library(shiny)
library(leaflet)

ui <- fluidPage(
  leafletOutput('map')
)

server <- function(input, output, session) {
  output$map <- renderLeaflet({leaflet()%>%addTiles()})

  observeEvent(input$map_click, {
    click = input$map_click
    leafletProxy('map')%>%addMarkers(lng = click$lng, lat = click$lat)
  })
}

shinyApp(ui, server)