@@ -87,19 +87,35 @@ knit_print.figure <- function(x, options, ...) {
87
87
# ' @param x a plotly object
88
88
# ' @param width attribute of the iframe
89
89
# ' @param height attribute of the iframe
90
+ # ' @param dir a directory for placing
91
+ # ' @param file a filename for saving the standalone HTML
92
+ # ' (only used if x is a non-figure object)
90
93
# ' @export
91
- embed_notebook <- function (x , width = " 100%" , height = " 525 " ) {
92
- if ( ! " figure " %in% class( x )) stop( " x must be a plotly figure " )
94
+ embed_notebook <- function (x , width = " 100%" , height = " 400 " ,
95
+ file = paste0( " plotlyJupyterHTML/ " , digest :: digest(Sys.time()), " .html " )) {
93
96
if (system.file(package = " IRdisplay" ) == " " ) {
94
97
warning(" You need the IRdisplay package to use this function: \n " ,
95
98
" devtools::install_github(c('IRkernel/repr', 'IRKernel/IRdisplay'))" )
96
99
return (x )
97
100
}
98
- iframe <- plotly_iframe(x $ url , width , height )
101
+ l <- plotly_build(x )
102
+ src <- if (is.null(l $ url )) {
103
+ dir <- dirname(file )
104
+ if (! dir.exists(dir )) dir.create(dir , recursive = TRUE )
105
+ owd <- setwd(dir )
106
+ on.exit(setwd(owd ), add = TRUE )
107
+ htmlwidgets :: saveWidget(as.widget(l ), file = basename(file ))
108
+ file
109
+ } else {
110
+ paste0(l $ url , " .embed" )
111
+ }
112
+ iframe <- plotly_iframe(src , width , height )
99
113
get(" display_html" , envir = asNamespace(" IRdisplay" ))(iframe )
100
114
}
101
115
102
116
plotly_iframe <- function (url , width , height ) {
103
- paste(" <iframe height=\" " , height , " \" id=\" igraph\" scrolling=\" no\" seamless=\" seamless\" src=\" " ,
104
- url , " .embed\" width=\" " , width , " \" frameBorder=\" 0\" ></iframe>" , sep = " " )
117
+ sprintf(
118
+ ' <iframe src="%s" width="%s" height="%s" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>' ,
119
+ url , width , height
120
+ )
105
121
}
0 commit comments