我创建了一个交互式地图,reactable
用于在地图上显示点,反之亦然(用户可以使用左侧的按钮在地图上选择区域以过滤表格中的相应数据)。问题是,当我想添加超过 1 层(另一个addCircleMarkers
)时,当我选择任何行时,整个表都会消失。所以,这一切都适用于一层,不适用于超过 1 层。在这种情况下是否可以添加额外的层?
这是可重现的代码(请取消注释第 2addCircleMarkers
层以查看消失的表):
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)