Skip to content

Commit 37c7183

Browse files
committed
highlight_key() is a better name than highlight_unit()
1 parent 80b3324 commit 37c7183

28 files changed

+65
-56
lines changed

Diff for: NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export(hide_colorbar)
142142
export(hide_guides)
143143
export(hide_legend)
144144
export(highlight)
145-
export(highlight_unit)
145+
export(highlight_key)
146146
export(knit_print.api_grid)
147147
export(knit_print.api_grid_local)
148148
export(knit_print.api_plot)

Diff for: NEWS.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
* The new `partial_bundle()` function makes it easy to leverage [partial bundles of plotly.js](https://github.com/plotly/plotly.js#partial-bundles) for reduced file sizes and faster render times.
2222
* The `config()` function gains a `locale` argument for easily changing localization defaults (#1270). This makes it possible localize date axes, and in some cases, modebar buttons (#1270).
2323
* The `plot_geo()` function gains a `offline` argument for rendering `"scattergeo"` traces with or without an internet connection (#356). Leveraging this argument requires the new **plotlyGeoAssets** package.
24+
* Support for async rendering of inside **shiny** apps using the [promises](https://rstudio.github.io/promises/) package (#1209). For an example, run `plotly_example("shiny", "async")`.
2425
* Instead of an error, `ggplotly(NULL, "message")` and `plotly_build(NULL, "message")` now returns `htmltools::div("message")`, making it easier to relay messages in shiny when data isn't yet ready to plot (#1116).
2526
* The `animation_button()` function gains a `label` argument, making it easier to control the label of an animation button generated through the `frame` API (#1205).
26-
* Support for async rendering of inside **shiny** apps using the [promises](https://rstudio.github.io/promises/) package (#1209). For an example, run `plotly_example("shiny", "async")`.
27+
* The new `highlight_key()` function provides a wrapper around `crosstalk::SharedData$new()`, making it easier to teach others how to leverage `SharedData` objects with **plotly** and **crosstalk**.
2728

2829
## CHANGES
2930

Diff for: R/ggplotly.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#' ggplotly(viz, tooltip = c("text", "size"))
4848
#'
4949
#' # linked scatterplot brushing
50-
#' d <- highlight_unit(mtcars)
50+
#' d <- highlight_key(mtcars)
5151
#' qplot(data = d, x = mpg, y = wt) %>%
5252
#' subplot(qplot(data = d, x = mpg, y = vs)) %>%
5353
#' layout(title = "Click and drag to select points") %>%
@@ -58,7 +58,7 @@
5858
#' demo("crosstalk-highlight-ggplotly", package = "plotly")
5959
#'
6060
#' # client-side linked brushing in a scatterplot matrix
61-
#' highlight_unit(iris) %>%
61+
#' highlight_key(iris) %>%
6262
#' GGally::ggpairs(aes(colour = Species), columns = 1:4) %>%
6363
#' ggplotly(tooltip = c("x", "y", "colour")) %>%
6464
#' highlight("plotly_selected")

Diff for: R/highlight.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@
5757
#' # These examples are designed to show you how to highlight/brush a *single*
5858
#' # view. For examples of multiple linked views, see `demo(package = "plotly")`
5959
#'
60-
#'
6160
#' library(crosstalk)
62-
#' d <- SharedData$new(txhousing, ~city)
61+
#' d <- highlight_key(txhousing, ~city)
6362
#' p <- ggplot(d, aes(date, median, group = city)) + geom_line()
6463
#' gg <- ggplotly(p, tooltip = "city")
6564
#' highlight(gg, dynamic = TRUE)

Diff for: R/plotly_data.R

+8-5
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,19 @@ print.plotly_data <- function(x, ...) {
8888
x
8989
}
9090

91-
#' Shared data
91+
#' Highlight/query data based on primary key
9292
#'
93-
#' This is simply a wrapper around `crosstalk::SharedData$new()` to make it easier
94-
#' to use and explain conceptually. It also makes it more discoverable if one
93+
#' This function simply creates an object of class [crosstalk::SharedData].
94+
#' The reason it exists is to make it easier to teach others how to leverage
95+
#' it's functionality in plotly. It also makes it more discoverable if one
9596
#' is already aware of [highlight].
9697
#'
97-
#' @param ... arguments passed to crosstalk::SharedData$new()
98+
#' @param ... arguments passed to `crosstalk::SharedData$new()`
9899
#' @export
100+
#' @author Carson Sievert
99101
#' @return An object of class [crosstalk::SharedData]
100-
highlight_unit <- function(...) {
102+
#' @seealso [highlight]
103+
highlight_key <- function(...) {
101104
crosstalk::SharedData$new(...)
102105
}
103106

Diff for: data-raw/res-us.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ res <- sf::st_read("~/Downloads/tl_2017_us_aiannh/tl_2017_us_aiannh.shp")
99
# (2) crosstalk highlight should set fillcolor...
1010

1111
res %>%
12-
highlight_unit(~NAME) %>%
12+
highlight_key(~NAME) %>%
1313
plot_ly(text = ~NAME) %>%
1414
highlight(selectize = TRUE, dynamic = TRUE)
1515

Diff for: demo/animation-tour-USArrests.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ax <- list(
4545
# for nicely formatted slider labels
4646
options(digits = 3)
4747

48-
tour_dat <- highlight_unit(tour_dat, ~state, group = "A")
48+
tour_dat <- highlight_key(tour_dat, ~state, group = "A")
4949

5050
tour <- proj_dat %>%
5151
plot_ly(x = ~x, y = ~y, frame = ~step, color = I("black")) %>%

Diff for: demo/crosstalk-filter-dynamic-axis.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ library(tidyr)
33
library(crosstalk)
44

55
m <- gather(mtcars, variable, value, -vs)
6-
msd <- highlight_unit(m, ~variable)
6+
msd <- highlight_key(m, ~variable)
77
gg <- ggplot(msd, aes(factor(vs), value)) +
88
geom_jitter(alpha = 0.3)
99

Diff for: demo/crosstalk-filter-lines.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ library(ggplot2)
33
library(gapminder)
44
library(plotly)
55

6-
sd <- highlight_unit(gapminder)
6+
sd <- highlight_key(gapminder)
77

88
g <- ggplot(sd, aes(year, lifeExp, color = country, group = country)) +
99
geom_line()

Diff for: demo/crosstalk-highlight-binned-target-a.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# These examples demonstrate ways to display binned/aggregated selections
22
library(plotly)
33

4-
d <- highlight_unit(mpg)
4+
d <- highlight_key(mpg)
55
dots <- plot_ly(d, colors = "Set1", color = ~class, x = ~displ, y = ~cyl) %>%
66
layout(
77
xaxis = list(title = "Engine displacement"),

Diff for: demo/crosstalk-highlight-binned-target-b.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# These examples demonstrate ways to display binned/aggregated selections
22
library(plotly)
33

4-
d <- highlight_unit(mtcars)
4+
d <- highlight_key(mtcars)
55
sp <- plot_ly(d, x = ~mpg, y = ~disp) %>%
66
add_markers(color = I("black"))
77

Diff for: demo/crosstalk-highlight-binned-target-c.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# These examples demonstrate ways to display binned/aggregated selections
22
library(plotly)
33

4-
tx <- highlight_unit(txhousing, ~city)
4+
tx <- highlight_key(txhousing, ~city)
55
p1 <- ggplot(tx, aes(date, median, group = city)) + geom_line() + xlab(NULL)
66
gg1 <- ggplotly(p1, tooltip = c("city", "date", "median"))
77
p2 <- plot_ly(tx, x = ~median, color = I("black")) %>%

Diff for: demo/crosstalk-highlight-epl-2.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dat <- england %>%
2020
mutate(meanP = mean(cumpts)) %>%
2121
filter(Season > 2006)
2222

23-
sd <- highlight_unit(dat, ~team, "Select a team")
23+
sd <- highlight_key(dat, ~team, "Select a team")
2424

2525
# a 'wormchart' like fig 8 here http://www.gradaanwr.net/wp-content/uploads/2016/06/dataApr16.pdf
2626
p <- ggplot(sd, aes(x = gameno, y = cumpts - meanP)) +

Diff for: demo/crosstalk-highlight-epl.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dat <- england %>%
1616
group_by(Season, team) %>%
1717
mutate(gameno = row_number(), cumpts = cumsum(pts))
1818

19-
sd <- highlight_unit(dat, ~Season, "Select a season")
19+
sd <- highlight_key(dat, ~Season, "Select a season")
2020

2121
p <- ggplot(sd, aes(x = gameno, y = cumpts)) +
2222
geom_line(aes(color = Season, group = Season), alpha = 0.5) +

Diff for: demo/crosstalk-highlight-ggpairs.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
library(GGally)
2-
d <- highlight_unit(iris)
2+
d <- highlight_key(iris)
33
p <- ggpairs(d, aes(colour = Species), columns = 1:5)
44
ggplotly(p) %>%
55
highlight("plotly_selected")

Diff for: demo/crosstalk-highlight-ggplotly.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
library(plotly)
22

33
# see https://vimeo.com/202647310
4-
d <- highlight_unit(txhousing, ~city, "Select a city")
4+
d <- highlight_key(txhousing, ~city, "Select a city")
55
p <- ggplot(d, aes(date, median, group = city)) + geom_line()
66
ggplotly(p, tooltip = "city") %>%
77
layout(title = "Click on a line to highlight a year") %>%
@@ -18,7 +18,7 @@ ggplotly(p) %>%
1818
layout(title = "Click on a line to highlight a year")
1919

2020
# perhaps a more useful example
21-
sd <- highlight_unit(txhousing, ~year)
21+
sd <- highlight_key(txhousing, ~year)
2222
p <- ggplot(sd, aes(month, median)) +
2323
geom_line(aes(group = year)) +
2424
geom_smooth(data = txhousing, method = "gam") +

Diff for: demo/crosstalk-highlight-intro.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ df <- data.frame(
1010
)
1111

1212
# delare the patient variable as the "unit of interest"
13-
sd <- highlight_unit(df, ~patient)
13+
sd <- highlight_key(df, ~patient)
1414

1515
p <- plot_ly(sd, x = ~visit, y = ~perc, color = I("black"),
1616
text = ~paste("Patient:", patient)) %>%

Diff for: demo/crosstalk-highlight-pipeline.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library(plotly)
22

3-
sd <- highlight_unit(txhousing, ~city, "Select a city")
3+
sd <- highlight_key(txhousing, ~city, "Select a city")
44

55
base <- plot_ly(sd, color = I("black"), height = 400) %>%
66
group_by(city)

Diff for: demo/crosstalk-highlight-subplot.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library(plotly)
22

3-
d <- highlight_unit(mtcars)
3+
d <- highlight_key(mtcars)
44
s <- subplot(
55
qplot(data = d, x = mpg, y = wt),
66
qplot(data = d, x = mpg, y = vs)

Diff for: demo/custom-javascript.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ onRender(p, "
5757

5858
# combine highlight() api with custom javascript
5959
mtcars %>%
60-
highlight_unit() %>%
60+
highlight_key() %>%
6161
plot_ly(x = ~wt, y = ~mpg, customdata = ~url) %>%
6262
highlight(color = "red") %>%
6363
onRender("

Diff for: demo/sf-dt.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ library(plotly)
22
library(crosstalk)
33

44
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
5-
ncsd <- highlight_unit(nc)
5+
ncsd <- highlight_key(nc)
66

77
map <- plot_ly(ncsd, split = ~NAME, color = I("gray"), hoveron = "fills") %>%
88
highlight(persistent = TRUE, color = "red", opacityDim = 1) %>%

Diff for: demo/sf-mapbox-data.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plot_mapbox(res_mn, split = ~INDRESNAME, span = I(1))
1010
plot_mapbox(res_mn, split = ~INDRESNAME, color = ~AREA, stroke = ~PERIMETER, span = I(1))
1111

1212
# linking with DT
13-
mn <- highlight_unit(res_mn)
13+
mn <- highlight_key(res_mn)
1414
bscols(
1515
plot_mapbox(mn, split = ~INDRESNAME, text = ~INDRESNAME, hoverinfo = "text", hoveron = "fills") %>%
1616
layout(title = "Click a reservation", showlegend = FALSE),
@@ -19,7 +19,7 @@ bscols(
1919

2020
# linking with plotly
2121
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
22-
ncsd <- highlight_unit(nc)
22+
ncsd <- highlight_key(nc)
2323

2424
# note that brushing counties is currently possible with plot_ly(), but isn't quite working
2525
# yet with plot_mapbox() -- https://github.com/plotly/plotly.js/issues/2512

Diff for: demo/sf-plotly-3D-globe.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ globe <- plot_ly(height = 500) %>%
4242
hoverinfo = "none"
4343
) %>%
4444
add_sf(
45-
data = highlight_unit(storms, group = "storm paths"),
45+
data = highlight_key(storms, group = "storm paths"),
4646
name = "storm paths",
4747
x = ~ 1.001 * cos(degrees2radians(x)) * cos(degrees2radians(y)),
4848
y = ~ 1.001 * sin(degrees2radians(x)) * cos(degrees2radians(y)),
@@ -97,7 +97,7 @@ distanceByAlt <- storms %>%
9797
group_by(L1) %>%
9898
mutate(dist = arc_dist(X, Y)) %>%
9999
rename(altitude = Z) %>%
100-
highlight_unit(~L1, group = "storm paths") %>%
100+
highlight_key(~L1, group = "storm paths") %>%
101101
plot_ly(x = ~dist, y = ~altitude, height = 400) %>%
102102
# plotly.js doesn't support color gradient along *2D* lines
103103
add_lines(color = I("gray")) %>%

Diff for: demo/sf-plotly-storms.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
library(plotly)
22

33
storms <- sf::st_read(system.file("shape/storms_xyz.shp", package = "sf"), quiet = TRUE)
4-
stormz <- highlight_unit(storms)
4+
stormz <- highlight_key(storms)
55

66
xy <- plot_ly(stormz, color = ~z, mode = "markers+lines", line = list(color = "gray"), hoverinfo = "none")
77
xz <- add_sf(xy, y = ~z, color = ~y)

Diff for: man/ggplotly.Rd

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

Diff for: man/highlight.Rd

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

Diff for: man/highlight_key.Rd

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

Diff for: man/highlight_unit.Rd

-19
This file was deleted.

0 commit comments

Comments
 (0)