@@ -31,31 +31,32 @@ knit_print.plotly_figure <- function(x, options, ...) {
31
31
# ' \code{plot_ly} is used. If that is also \code{NULL}, '100\%' is the default.
32
32
# ' @param height attribute of the iframe. If \code{NULL}, the height in
33
33
# ' \code{plot_ly} is used. If that is also \code{NULL}, '400px' is the default.
34
- # ' @param file a filename for saving the standalone HTML
35
- # ' (only used if x is a non-figure object)
36
34
# ' @export
37
- embed_notebook <- function (x , width = NULL , height = NULL ,
38
- file = paste0(" plotlyJupyterHTML/" , digest :: digest(Sys.time()), " .html" )) {
35
+ embed_notebook <- function (x , width = NULL , height = NULL ) {
39
36
if (system.file(package = " IRdisplay" ) == " " ) {
40
37
warning(" You need the IRdisplay package to use this function: \n " ,
41
38
" devtools::install_github(c('IRkernel/repr', 'IRKernel/IRdisplay'))" )
42
39
return (x )
43
40
}
44
- l <- plotly_build(x )
45
- src <- if (is.null(l $ url )) {
46
- dir <- dirname(file )
47
- if (! dir.exists(dir )) dir.create(dir , recursive = TRUE )
48
- owd <- setwd(dir )
49
- on.exit(setwd(owd ), add = TRUE )
50
- htmlwidgets :: saveWidget(l , file = basename(file ))
51
- file
52
- } else {
53
- l $ url
41
+ UseMethod(" embed_notebook" )
42
+ }
43
+
44
+ # ' @export
45
+ embed_notebook.plotly <- function (x , width = NULL , height = NULL ) {
46
+ p <- plotly_build(x )
47
+ p $ width <- width %|| % p $ width
48
+ p $ height <- height %|| % p $ height
49
+ html <- getFromNamespace(" toHTML" , asNamespace(" htmlwidgets" ))(p )
50
+ # if we've already printed a plotly object, remove it's dependencies
51
+ if (! is.null(last_plot())) {
52
+ htmltools :: htmlDependencies(html ) <- NULL
54
53
}
55
- iframe <- plotly_iframe(src , width %|| % l $ width , height %|| % l $ height , url_ext = " " )
56
- get(" display_html" , envir = asNamespace(" IRdisplay" ))(iframe )
54
+ get(" display_html" , envir = asNamespace(" IRdisplay" ))(as.character(html ))
57
55
}
58
56
57
+ # TODO: provide method for api_figure objects
58
+
59
+
59
60
plotly_iframe <- function (url = " " , width = NULL , height = NULL , url_ext = " .embed" ) {
60
61
url <- paste0(url , url_ext )
61
62
sprintf(
0 commit comments