Leaflet in R plotting icons unpredictably

前端 未结 1 520
后悔当初
后悔当初 2021-02-10 16:11

My Shiny app takes a dataframe like this:

and subsets appropriately by allowing the user to select a person (P1_name) and a date (date

1条回答
  •  你的背包
    2021-02-10 16:53

    One of the issue could be that you are adding empty markers in your subsets and leaflet reacts strangely to that.

    For example, when you select Joe Blow, all the subsets for P1_outcome == "W", "L" or "D" are empty.

    As described here, you could use the iconList function to change the icons depending on P1_outcome and remove all the subset.

    You could for example add:

    icon_list <- iconList(W=icon_W,L=icon_L,D=icon_D,N=icon_N)
    

    right after you define all the icons, and use:

    m <- leaflet(DF) %>%
          addTiles() %>%  # Add default OpenStreetMap map tiles
          setView(lat=setzoom[1], lng=setzoom[2], zoom=zoom_num) %>%
          addMarkers(lat=DF$lat, lng=DF$lon,icon= ~icon_list[DF$P1_outcome]) 
    

    to create your map.

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