Click on points in a leaflet map as input for a plot in shiny

后端 未结 1 1155
执念已碎
执念已碎 2021-01-03 02:23

Using the example below, I am trying to figure out a way to add functionality to my shiny app such that the following works:

  1. Click on a point on the map
  2. <
1条回答
  •  别那么骄傲
    2021-01-03 03:08

    You can use input$map_marker_click and updateSelectInput():

    Edit: Added functionality that stations can be deleted from selectInput() as suggested by OP in the comments.

    (Dont forget to add session to your sever function).

    observeEvent(input$stations,{
      updateSelectInput(session, "stations", "Click on Station", 
                        choices = levels(factor(quakes$stations)), 
                        selected = c(input$stations))
    })
    
    observeEvent(input$map_marker_click, {
      click <- input$map_marker_click
      station <- quakes[which(quakes$lat == click$lat & quakes$long == click$lng), ]$stations
      updateSelectInput(session, "stations", "Click on Station", 
                        choices = levels(factor(quakes$stations)), 
                        selected = c(input$stations, station))
    })
    

    However, this functionality is partly overwritten by the popup event(?). As i see it there is an inner blue circle (darker blue) that if clicked produces the popup. However, the input$map_marker_click only works if you click the outer (light blue) circle. I would report it as a bug,...

    0 讨论(0)
提交回复
热议问题