Skip to content

Commit f7b5710

Browse files
committed
query dplyr groups from data only if the relevant trace has a notion of group, closes #1351
1 parent 3108764 commit f7b5710

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

R/plotly_build.R

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,24 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
131131
class = oldClass(x)
132132
)
133133

134+
# determine trace type (if not specified, can depend on the # of data points)
135+
# note that this should also determine a sensible mode, if appropriate
136+
trace <- verify_type(trace)
137+
# verify orientation of boxes/bars
138+
trace <- verify_orientation(trace)
139+
134140
# attach crosstalk info, if necessary
135141
if (crosstalk_key() %in% names(dat) && isTRUE(trace[["inherit"]] %||% TRUE)) {
136142
trace[["key"]] <- trace[["key"]] %||% dat[[crosstalk_key()]]
137143
trace[["set"]] <- trace[["set"]] %||% attr(dat, "set")
138144
}
139145

140146
# if appropriate, tack on a group index
141-
grps <- tryCatch(
142-
as.character(dplyr::groups(dat)),
143-
error = function(e) character(0)
144-
)
145-
147+
grps <- if (has_group(trace)) dplyr::group_vars(dat)
146148
if (length(grps) && any(lengths(trace) == NROW(dat))) {
147149
trace[[".plotlyGroupIndex"]] <- interaction(dat[, grps, drop = F])
148150
}
149151

150-
# determine trace type (if not specified, can depend on the # of data points)
151-
# note that this should also determine a sensible mode, if appropriate
152-
trace <- verify_type(trace)
153-
# verify orientation of boxes/bars
154-
trace <- verify_orientation(trace)
155-
156152
# add sensible axis names to layout
157153
for (i in c("x", "y", "z")) {
158154
nm <- paste0(i, "axis")

0 commit comments

Comments
 (0)