Skip to content

Commit a51532d

Browse files
committed
Disambiguate classnames
Change the class of the plot_ly object (built but not widgetized) to plotly_hash, and simplify print/knit_print methods. This fixes compatibility issues with RStudio's upcoming R Notebook feature.
1 parent 43d882d commit a51532d

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

NAMESPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ S3method(geom2trace,GeomText)
1212
S3method(geom2trace,GeomTile)
1313
S3method(geom2trace,default)
1414
S3method(print,figure)
15-
S3method(print,plotly)
15+
S3method(print,plotly_hash)
1616
S3method(to_basic,GeomAbline)
1717
S3method(to_basic,GeomArea)
1818
S3method(to_basic,GeomBoxplot)
@@ -49,7 +49,7 @@ export(get_figure)
4949
export(gg2list)
5050
export(ggplotly)
5151
export(knit_print.figure)
52-
export(knit_print.plotly)
52+
export(knit_print.plotly_hash)
5353
export(last_plot)
5454
export(layout)
5555
export(offline)

R/print.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#' @export
66
#' @importFrom htmlwidgets createWidget
77
#' @importFrom htmlwidgets sizingPolicy
8-
print.plotly <- function(x, ...) {
9-
if (!inherits(x, "htmlwidget")) x <- as.widget(x)
10-
get("print.htmlwidget", envir = asNamespace("htmlwidgets"))(x, ...)
8+
print.plotly_hash <- function(x, ...) {
9+
x <- as.widget(x)
10+
print(x, ...)
1111
}
1212

1313
#' Print a plotly object in a knitr doc
@@ -16,9 +16,9 @@ print.plotly <- function(x, ...) {
1616
#' @param options knitr options.
1717
#' @param ... additional arguments
1818
#' @export
19-
knit_print.plotly <- function(x, options, ...) {
20-
if (!inherits(x, "htmlwidget")) x <- as.widget(x)
21-
get("knit_print.htmlwidget", envir = asNamespace("htmlwidgets"))(x, options = options, ...)
19+
knit_print.plotly_hash <- function(x, options, ...) {
20+
x <- as.widget(x)
21+
knitr::knit_print(x, options, ...)
2222
}
2323

2424
#' Convert a plotly object to an htmlwidget object

R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ hash_plot <- function(df, p) {
3636
assign(hash, p, envir = plotlyEnv)
3737
attr(df, "plotly_hash") <- hash
3838
# add plotly class mainly for printing method
39-
class(df) <- unique(c("plotly", class(df)))
39+
class(df) <- unique(c("plotly_hash", class(df)))
4040
# return a data frame to be compatible with things like dplyr
4141
df
4242
}

man/knit_print.plotly.Rd renamed to man/knit_print.plotly_hash.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/print.plotly.Rd renamed to man/print.plotly_hash.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)