I created an interactive map along with reactable which I use to show points on the map and the other way round (user can select area on the map using button on the left to filter corresponding data in a table). The issue is that when I want to add more than 1 layer (another addCircleMarkers) then the whole table disappears when I select any row. So, it all works fine with one layer, doesn't work with more than 1. Is it possible to add additional layers in this case?
Here is reproducible code (please uncomment 2-nd addCircleMarkers layer to see disappearing table):
library(crosstalk)
library(leaflet)
library(dplyr)
library(reactable)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
),
mainPanel(
tagList(
leaflet::leafletOutput("map"),
reactable::reactableOutput("table")
))
)
)
server <- function(input, output) {
# data to render in a table
data_all <- quakes %>%
dplyr::select(depth, mag, stations) %>%
crosstalk::SharedData$new(group = "volcano")
# data to render on a map
df_sf <- quakes %>%
sf::st_as_sf(coords = c("long","lat"), crs = 4326)
df_sf_ALL <- crosstalk::SharedData$new(df_sf, group = "volcano")
df_less_20 <- quakes %>%
dplyr::filter(stations<20) %>%
sf::st_as_sf(coords = c("long","lat"), crs = 4326)
df_more_20 <- quakes %>%
dplyr::filter(stations>20) %>%
sf::st_as_sf(coords = c("long","lat"), crs = 4326)
df_sf_less_20 <- crosstalk::SharedData$new(df_less_20, group = "volcano")
df_sf_more_20 <- crosstalk::SharedData$new(df_more_20, group = "volcano")
output$map <- leaflet::renderLeaflet({
leaflet::leaflet(df_sf_ALL) %>%
leaflet::addTiles() %>%
#leaflet::addCircleMarkers(data = df_sf_less_20, fillColor = "red", stroke = FALSE) %>%
leaflet::addCircleMarkers(data = df_sf_more_20, fillColor = "green", stroke = FALSE)
})
output$table <- reactable::renderReactable({
reactable::reactable(
data_all,
selection = "multiple",
onClick = "select",
rowStyle = list(cursor = "pointer"),
minRows = 10
)
})
}
shinyApp(ui = ui, server = server)