demo/crosstalk-highlight-leaflet.R

library(plotly)
library(crosstalk)
library(htmltools)

# leaflet should respect these "global" highlight() options
options(opacityDim = 0.5)

sd <- highlight_key(quakes)

p <- plot_ly(sd, x = ~depth, y = ~mag) %>% 
  add_markers(alpha = 0.5) %>%
  highlight("plotly_selected", dynamic = TRUE)

# Requires devtools::install_github("rstudio/leaflet#346")
withr::with_namespace("leaflet", {
  map <- leaflet(sd) %>% 
    addTiles() %>% 
    addCircles()
})

bscols(p, map)

Try the plotly package in your browser

Any scripts or data that you put into this service are public.

plotly documentation built on June 20, 2025, 1:09 a.m.