diff --git a/R/ggplotly.R b/R/ggplotly.R index a1ab6b6522..e79776469f 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -690,8 +690,8 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A l <- list(data = setNames(traces, NULL), layout = compact(gglayout)) # ensure properties are boxed correctly l <- add_boxed(rm_asis(l)) - l$width <- width - l$height <- height + l$layout$width <- width + l$layout$height <- height l$source <- source structure(l, class = "plotly_built") } diff --git a/R/plotly.R b/R/plotly.R index 5e2a6eaaa1..e266930c06 100644 --- a/R/plotly.R +++ b/R/plotly.R @@ -95,10 +95,8 @@ plot_ly <- function(data = data.frame(), ..., type = "scatter", # plotly objects should always have a _list_ of trace(s) p <- list( data = list(tr), - layout = NULL, + layout = list(width = width, height = height), url = NULL, - width = width, - height = height, source = source ) diff --git a/R/print.R b/R/print.R index a22c9a65dd..8916ea0ece 100644 --- a/R/print.R +++ b/R/print.R @@ -60,8 +60,8 @@ as.widget <- function(x, ...) { htmlwidgets::createWidget( name = "plotly", x = x, - width = x$width, - height = x$height, + width = x$layout$width, + height = x$layout$height, sizingPolicy = htmlwidgets::sizingPolicy( padding = 5, browser.fill = TRUE, diff --git a/inst/htmlwidgets/plotly.js b/inst/htmlwidgets/plotly.js index e9a3f90eda..ce0319ed11 100644 --- a/inst/htmlwidgets/plotly.js +++ b/inst/htmlwidgets/plotly.js @@ -31,6 +31,9 @@ HTMLWidgets.widget({ instance.plotly = true; instance.autosize = x.layout.autosize; } else { + // for some reason, we must explictly set this explicitly? + // https://github.com/plotly/plotly.js/issues/537 + x.layout.autosize = true; Plotly.newPlot(graphDiv, x.data, x.layout); }