From cbe30cce78693ccfdfafaa2b2e4e878afc3574b9 Mon Sep 17 00:00:00 2001 From: Roman Zenka Date: Fri, 21 Feb 2025 16:07:53 -0600 Subject: [PATCH] Protect list of variables If this is not done (or similar), in rare situations the `recurse` function splits the variable list into parts if it happens to match length of the column to split by. Fixes #2419 --- NEWS.md | 1 + R/plotly_build.R | 2 ++ 2 files changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 6df45bbe93..88ea52da96 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,7 @@ * Closed #2337: Creating a new `event_data()` handler no longer causes a spurious reactive update of existing `event_data()`s. (#2339) * Closed #2376: Removes errant boxmode warning for grouped boxplot. (#2396) +* Closed #2419: Issue with NA handling in scatter plots: Two NAs per category cause incorrect line connection (#2419) # 4.10.4 diff --git a/R/plotly_build.R b/R/plotly_build.R index ad9f62c704..eee14917ce 100644 --- a/R/plotly_build.R +++ b/R/plotly_build.R @@ -995,10 +995,12 @@ traceify <- function(dat, x = NULL) { recurse <- function(z, n, idx) { if (is.list(z)) lapply(z, recurse, n, idx) else if (length(z) == n) z[idx] else z } + varMapping <- dat[[".plotlyVariableMapping"]] # Protect this value from recurse new_dat <- list() for (j in seq_along(lvls)) { new_dat[[j]] <- lapply(dat, function(y) recurse(y, n, x %in% lvls[j])) new_dat[[j]]$name <- new_dat[[j]]$name %||% lvls[j] + new_dat[[j]]$.plotlyVariableMapping <- varMapping } return(new_dat) }