0

I am working with multivariant data linking Leaflet and d3scatter plots. It works well for one variable. If I try to include a second variable in Leaflet by a second addCircleMarkers and addLayersControl then the sharedData links break, the filtering doesn't work and the brushing doesn't work. Thanks in advance. A MWE is attached:

library("crosstalk")
library("d3scatter")
library("leaflet")

Long <- c(117.4,117.5,117.6)
Lat<- c(-33.7,-33.8,-33.9)
var1 <- c(21,22,23)
var2 <- c(31,32,33)
species <- c(8,9,10)

df1<- data.frame(Long, Lat, var1, var2, species)
sdf1 <- SharedData$new(df1)

col_1 <- c( "yellow" ,"black" ,"orange")
col_2 <- c("red" ,"green" ,"blue")


l <- leaflet(sdf1)%>% 
  setView(117.5, -33.8, 10) %>% 
  addCircleMarkers(radius = 1, color = col_1, group = "1") %>%
#  addCircleMarkers(radius = 1, color =  col_2, group = "2") %>%
# PROBLEM  -  adding the second "addCircleMarkers" enables the overlayGroups but 
#             it breaks the link between the plots and breaks the filter
  addLayersControl(overlayGroups=c("1","2"))


m <- list(l, filter_checkbox("unique_id_for_species", "Animal Species", sdf1, ~species))
n <- list(d3scatter(sdf1, ~var2, ~var1, color = ~species, x_lim = c(30,40), y_lim = c(20,25), width="70%",  height=200),
          d3scatter(sdf1, ~var1, ~var2, color = ~species, y_lim = c(30,40), x_lim = c(20,25), width="70%",  height=200))

bscols(m, n)
paulc
  • 1
  • 1
  • I have checked out "https://stackoverflow.com/questions/62817005/r-leaflet-assign-multiple-groups-to-a-layer-to-filter-data-and-change-column-re" but the issue occurs in this code also – paulc Sep 21 '20 at 01:44
  • I have sorted this by using Shiny - observe({ leafletProxy("map", data = sdf1) %>% clearMarkers() %>% addCircleMarkers(data = sdf1, color = ~pal(eval(as.symbol(input$var)))) }) – paulc Sep 22 '20 at 02:47

0 Answers0