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

NAMESPACE

Lines changed: 1 addition & 1 deletion
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)

NEWS.md

Lines changed: 2 additions & 1 deletion
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

R/ggplotly.R

Lines changed: 2 additions & 2 deletions
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")

R/highlight.R

Lines changed: 1 addition & 2 deletions
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)

R/plotly_data.R

Lines changed: 8 additions & 5 deletions
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

data-raw/res-us.R

Lines changed: 1 addition & 1 deletion
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

demo/animation-tour-USArrests.R

Lines changed: 1 addition & 1 deletion
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")) %>%

demo/crosstalk-filter-dynamic-axis.R

Lines changed: 1 addition & 1 deletion
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

demo/crosstalk-filter-lines.R

Lines changed: 1 addition & 1 deletion
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()

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

Lines changed: 1 addition & 1 deletion
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"),

0 commit comments

Comments
 (0)