@@ -221,21 +221,46 @@ style <- function(p = last_plot(), ..., traces = 1, evaluate = FALSE) {
221
221
hash_plot(data , p )
222
222
}
223
223
224
- # ' Build a plotly object before viewing it
224
+ # ' Create a 'plotly_built' object
225
225
# '
226
- # ' For convenience and efficiency purposes, plotly objects are subject to lazy
227
- # ' evaluation. That is, the actual content behind a plotly object is not
228
- # ' created until it is absolutely necessary. In some instances, you may want
229
- # ' to perform this evaluation yourself, and work directly with the resulting
230
- # ' list.
226
+ # ' This generic function creates the list object sent to plotly.js
227
+ # ' for rendering. Using this function can be useful for overriding defaults
228
+ # ' provided by \code{ggplotly}/\code{plot_ly} or for debugging rendering
229
+ # ' errors.
231
230
# '
232
- # ' @param l a ggplot object, or a plotly object, or a list.
231
+ # ' @param l a ggplot object, or a plotly_hash object, or a list.
233
232
# ' @export
233
+ # ' @examples
234
+ # '
235
+ # ' p <- plot_ly()
236
+ # ' # data frame
237
+ # ' str(p)
238
+ # ' # the actual list of options sent to plotly.js
239
+ # ' str(plotly_build(p))
240
+ # '
241
+ # ' p <- qplot(data = mtcars, wt, mpg, geom = c("point", "smooth"))
242
+ # ' l <- plotly_build(p)
243
+ # ' # turn off hoverinfo for the smooth (but keep it for the points)
244
+ # ' l$data[[2]]$hoverinfo <- "none"
245
+ # ' l$data[[3]]$hoverinfo <- "none"
246
+ # ' l
247
+ # '
234
248
plotly_build <- function (l = last_plot()) {
235
- # ggplot objects (including ggmatrix) don't need any special type of handling
236
- if (inherits(l , " gg" )) {
237
- return (structure(get_plot(ggplotly(l )), class = " plotly" ))
238
- }
249
+ UseMethod(" plotly_build" )
250
+ }
251
+
252
+ # ' @export
253
+ plotly_build.plotly_built <- function (l = last_plot()) {
254
+ l
255
+ }
256
+
257
+ # ' @export
258
+ plotly_build.gg <- function (l = last_plot()) {
259
+ structure(get_plot(ggplotly(l )), class = " plotly_built" )
260
+ }
261
+
262
+ # ' @export
263
+ plotly_build.plotly_hash <- function (l = last_plot()) {
239
264
l <- get_plot(l )
240
265
# assume unnamed list elements are data/traces
241
266
nms <- names(l )
0 commit comments