title: How to update coordinates after dragging a marker in leaflet shiny?
body: <p>I want to have an app, which generates new points on click, similar to here:
  <a href="https://stackoverflow.com/questions/34348737/r-leaflet-how-to-click-on-map-and-add-a-circle">R leaflet how to click on map and add a circle</a></p>
  
  <p>But the markers should be draggable and when dragged, the coordinates should be updated, shown in the dataTable. I have achieved this with a mouseout event. I found this solution, but if I set two points both will have the same coordinates (from the second point) and only will be refreshed, when mouseout is triggered.</p>
  
  <pre><code>library(shiny)
  library(leaflet)
  
  df &lt;- data.frame(longitude = 10.5, latitude = 48)
  
  ui &lt;- fluidPage(
    navbarPage("Title",
           tabPanel("Map",
                    mainPanel(leafletOutput("map", width = "100%", height = "700")
                    )),
           tabPanel("Data", dataTableOutput("table"))
   )
  )
  
  server &lt;- function(input, output) {
  
   output$map &lt;- renderLeaflet({
     leaflet() %&gt;% addTiles()
   })
  
   df_r &lt;- reactiveValues(new_data = df)
  
   # reactive list with id of added markers
   clicked_markers &lt;- reactiveValues(clickedMarker = NULL)
  
   observeEvent(input$map_click, {
     click &lt;- input$map_click
     click_lat &lt;- click$lat
     click_long &lt;- click$lng
  
     clicked_markers$clickedMarker &lt;- c(clicked_markers$clickedMarker, 1)
     id &lt;- length(clicked_markers$clickedMarker)
  
  
  # Add the marker to the map
     leafletProxy('map') %&gt;%
      addMarkers(lng = click_long, lat = click_lat, group = 'new_circles',
                 options = markerOptions(draggable = TRUE), layerId = id) 
  
  # add new point to dataframe
     df_r$new_data &lt;- rbind(rep(NA, ncol(df)), df_r$new_data)
     df_r$new_data$longitude[1] &lt;- click_long
     df_r$new_data$latitude[1] &lt;- click_lat
   })
  
   # update coordinates of marker on mouseout
   # how do I select the right row in the dataframe? layerId?
   observeEvent(input$map_marker_mouseout,{
     click_marker &lt;- input$map_marker_mouseout
     id &lt;- input$map_marker_mouseout$id
  
     if(click_marker$lng != df_r$new_data$longitude[id] | click_marker$lat != df_r$new_data$latitude[id]){ # why is this always true??
       df_r$new_data$longitude[id] &lt;- click_marker$lng
       df_r$new_data$latitude[id] &lt;- click_marker$lat
     }
   })
  
   output$table &lt;- renderDataTable({df_r$new_data})
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>