Skip to content

Commit 66c73be

Browse files
committed
fall back on height/width of built plot
1 parent 7d1b463 commit 66c73be

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

R/print.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ knit_print.figure <- function(x, options, ...) {
8585

8686
#' Embed a plotly figure as an iframe into a IPython Notebook
8787
#' @param x a plotly object
88-
#' @param width attribute of the iframe
89-
#' @param height attribute of the iframe
88+
#' @param width attribute of the iframe. If \code{NULL}, the width in
89+
#' \code{plot_ly} is used. If that is also \code{NULL}, '100\%' is the default.
90+
#' @param height attribute of the iframe. If \code{NULL}, the height in
91+
#' \code{plot_ly} is used. If that is also \code{NULL}, '400px' is the default.
9092
#' @param dir a directory for placing
9193
#' @param file a filename for saving the standalone HTML
9294
#' (only used if x is a non-figure object)
9395
#' @export
94-
embed_notebook <- function(x, width = "100%", height = "400",
96+
embed_notebook <- function(x, width = NULL, height = NULL,
9597
file = paste0("plotlyJupyterHTML/", digest::digest(Sys.time()), ".html")) {
9698
if (system.file(package = "IRdisplay") == "") {
9799
warning("You need the IRdisplay package to use this function: \n",
@@ -109,13 +111,13 @@ embed_notebook <- function(x, width = "100%", height = "400",
109111
} else {
110112
paste0(l$url, ".embed")
111113
}
112-
iframe <- plotly_iframe(src, width, height)
114+
iframe <- plotly_iframe(src, width %||% l$width, height %||% l$height)
113115
get("display_html", envir = asNamespace("IRdisplay"))(iframe)
114116
}
115117

116-
plotly_iframe <- function(url, width, height) {
118+
plotly_iframe <- function(url = "", width = NULL, height = NULL) {
117119
sprintf(
118120
'<iframe src="%s" width="%s" height="%s" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>',
119-
url, width, height
121+
url, width %||% "100%", height %||% "400"
120122
)
121123
}

man/embed_notebook.Rd

Lines changed: 5 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)