I have two separate dataframes that include a common key that I'm attempting to map with leaflet and provide filtering through crosstalk. For this application, shiny is not an option since these will be standalone webpages that are upload to Sharepoint for viewing.
The first dataframe is a list of locations and the second dataframe is list of other locations that are related to the first. The goal would be to use filter_select to filter for the first location and have the map show a marker for that and then a different kind of marker for the related locations. If I do either one of these, the crosstalk filter works fine. If I try to add both, the filter no longer works.
This also breaks if I put everything into a single dataframe and try two different addMarkers calls which is similar to this unanswered question: Crosstalk links broken by second Leaflet addCircleMarkers call
Any help would be appreciated!
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(dplyr) ; library(flexdashboard) ; library(crosstalk) ; library(leaflet)
foo <- data.frame(
id = rep(1:5), lat = runif(5, 34, 40), lng = runif(5, 118, 123) * -1
)
bar <- data.frame(
id = rep(1:5, times = 5, each = 3), lat = runif(15, 34, 40), lng = runif(15, 118, 123) * -1
)
sd_foo <- SharedData$new(foo, group = "foo", key = ~id)
sd_bar <- SharedData$new(bar, group = "foo", key = ~id)
```
Column {data-width=100}
-----------------------------------------------------------------------
### Filter
```{r}
filter_select("id", "Select ID:", sd_foo, ~id, multiple = FALSE)
```
Column {data-width=500}
-----------------------------------------------------------------------
### Map
```{r}
leaflet(sd_foo) %>%
addTiles() %>%
addMarkers() %>%
addCircleMarkers(data = sd_bar)
```