Skip to content

Commit d0384b3

Browse files
committed
improve demos (and don't force persistence unless it makes sense)
1 parent e8d195f commit d0384b3

7 files changed

+14
-30
lines changed

R/highlight.R

+3-8
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@
6060
#' d <- SharedData$new(txhousing, ~city)
6161
#' p <- ggplot(d, aes(date, median, group = city)) + geom_line()
6262
#' gg <- ggplotly(p, tooltip = "city")
63-
#' highlight(gg, persistent = TRUE, dynamic = TRUE)
63+
#' highlight(gg, dynamic = TRUE)
6464
#'
6565
#' # supply custom colors to the brush
6666
#' cols <- toRGB(RColorBrewer::brewer.pal(3, "Dark2"), 0.5)
67-
#' highlight(
68-
#' gg, on = "plotly_hover", color = cols, persistent = TRUE, dynamic = TRUE
69-
#' )
67+
#' highlight(gg, on = "plotly_hover", color = cols, dynamic = TRUE)
7068
#'
7169
#' # Use attrs_selected() for complete control over the selection appearance
7270
#' # note any relevant colors you specify here should override the color argument
@@ -76,10 +74,7 @@
7674
#' marker = list(symbol = "x")
7775
#' )
7876
#'
79-
#' highlight(
80-
#' layout(gg, showlegend = TRUE),
81-
#' selected = s, persistent = TRUE
82-
#' )
77+
#' highlight(layout(gg, showlegend = TRUE), selected = s)
8378
#'
8479

8580
highlight <- function(p, on = "plotly_click", off,

demo/crosstalk-highlight-binned-target-c.R

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,4 @@ p2 <- plot_ly(tx, x = ~median, color = I("black")) %>%
1010

1111
subplot(gg1, p2, titleX = TRUE, titleY = TRUE) %>%
1212
layout(barmode = "overlay") %>%
13-
highlight(
14-
dynamic = TRUE, persistent = TRUE,
15-
selected = attrs_selected(opacity = 0.3)
16-
)
13+
highlight(dynamic = TRUE, selected = attrs_selected(opacity = 0.3))

demo/crosstalk-highlight-epl-2.R

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ gg <- ggplotly(p, width = 1050, height = 600, tooltip = "team")
3737

3838
highlight(
3939
gg,
40-
persistent = TRUE,
4140
dynamic = TRUE,
4241
selectize = TRUE,
4342
color = RColorBrewer::brewer.pal(12, "Paired")

demo/crosstalk-highlight-intro.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ p %>%
4646

4747
# By default, all selections are transient, meaning prior selections are
4848
# removed from the selection set before new selections are added. To prevent
49-
# prior selections from being removed, simply set the persistent argument to
50-
# `TRUE`.
51-
highlight(p, on = "plotly_hover", persistent = TRUE)
49+
# prior selections from being removed, hold down the shift key while triggering
50+
# the event
51+
highlight(p, on = "plotly_hover")
5252

5353
# Sometimes its useful to compare two or more different selection sets.
5454
# For example, how do patients with a high response on visit 1 compare to those
@@ -57,10 +57,10 @@ highlight(p, on = "plotly_hover", persistent = TRUE)
5757
# a colourpicker htmlwidget (@colourpicker) will appear just above the plotly
5858
# visualization. At any given time, the value of this widget controls the
5959
# color of new selection(s).
60-
highlight(p, on = "plotly_hover", persistent = TRUE, dynamic = TRUE)
60+
highlight(p, on = "plotly_hover", dynamic = TRUE)
6161

6262
# By default, the colourpicker widget uses colors from the "Set1"
6363
# colour brewer palette (@RColorBrewer), but any set of valid R colors can
6464
# be supplied to the color argument.
6565
colors <- RColorBrewer::brewer.pal(4, "Dark2")
66-
highlight(p, on = "plotly_hover", color = colors, dynamic = TRUE, persistent = TRUE)
66+
highlight(p, on = "plotly_hover", color = colors, dynamic = TRUE)

demo/crosstalk-highlight-leaflet.R

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ library(crosstalk)
55
library(htmltools)
66

77
# leaflet should respect these "global" highlight() options
8-
options(
9-
opacityDim = 0.5, persistent = TRUE
10-
)
8+
options(opacityDim = 0.5)
119

1210
sd <- SharedData$new(quakes)
1311

demo/crosstalk-highlight-pipeline.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ p2 <- base %>%
2424
subplot(p1, p2, titleX = TRUE, widths = c(0.3, 0.7)) %>%
2525
layout(margin = list(l = 120)) %>%
2626
hide_legend() %>%
27-
highlight(dynamic = TRUE, persistent = TRUE, selectize = TRUE)
27+
highlight(dynamic = TRUE, selectize = TRUE)

man/highlight.Rd

+3-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)