Skip to content

Commit dc653da

Browse files
committed
relay inherit info to the build step and don't attach crosstalk key/set when it is FALSE; fixes #1242
1 parent a35a817 commit dc653da

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

R/add.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ add_trace <- function(p, ...,
5757

5858
# "native" plotly arguments
5959
attrs <- list(...)
60+
attrs$inherit <- inherit
6061

6162
if (!is.null(attrs[["group"]])) {
6263
warning("The group argument has been deprecated. Use group_by() or split instead.")

R/plotly_build.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
132132
)
133133

134134
# attach crosstalk info, if necessary
135-
if (crosstalk_key() %in% names(dat)) {
135+
if (crosstalk_key() %in% names(dat) && isTRUE(trace[["inherit"]])) {
136136
trace[["key"]] <- trace[["key"]] %||% dat[[crosstalk_key()]]
137137
trace[["set"]] <- trace[["set"]] %||% attr(dat, "set")
138138
}
@@ -310,7 +310,7 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
310310
mappingAttrs <- c(
311311
"alpha", "alpha_stroke", npscales(), paste0(npscales(), "s"),
312312
".plotlyGroupIndex", ".plotlyMissingIndex",
313-
".plotlyTraceIndex", ".plotlyVariableMapping"
313+
".plotlyTraceIndex", ".plotlyVariableMapping", "inherit"
314314
)
315315
for (j in mappingAttrs) {
316316
traces[[i]][[j]] <- NULL

tests/testthat/test-animate-highlight.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,32 @@ test_that("SharedData produces key/set in ggplotly", {
2424
expect_false(tr$`_isSimpleKey` %||% FALSE)
2525
})
2626

27+
28+
29+
test_that("crosstalk keys are inherited in a layer with inherit = FALSE", {
30+
31+
p <- txhousing %>%
32+
group_by(city) %>%
33+
crosstalk::SharedData$new(~city, "Select a city") %>%
34+
plot_ly(x = ~date, y = ~median) %>%
35+
add_lines(alpha = 0.2) %>%
36+
add_ribbons(
37+
x = c(2016, 2017), ymin = c(150000, 160000), ymax = c(200000, 190000),
38+
inherit = FALSE
39+
)
40+
41+
b <- plotly_build(p)
42+
# second trace should have key/set info
43+
expect_null(b$x$data[[2]][["key"]])
44+
expect_null(b$x$data[[2]][["set"]])
45+
# first trace should
46+
k <- unique(b$x$data[[1]]$key)
47+
expect_equal(sort(k[!is.na(k)]), sort(unique(txhousing$city)))
48+
expect_true(b$x$data[[1]][["set"]] == "Select a city")
49+
})
50+
51+
52+
2753
# Ignore for now https://github.com/ggobi/ggally/issues/264
2854
#test_that("SharedData produces key/set in ggpairs", {
2955
# p <- GGally::ggpairs(m, columns = 1:3)

0 commit comments

Comments
 (0)