Skip to content

Commit d2b521e

Browse files
Jeffrey Shennumbers
Jeffrey Shen
authored and
numbers
committed
Support renderValue within iframe
1 parent 2368c0c commit d2b521e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

inst/htmlwidgets/plotly.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,15 @@ HTMLWidgets.widget({
155155
x.config.modeBarButtonsToRemove.push("sendDataToCloud");
156156
}
157157

158+
// if the object was passed in from another window, plotly will falsely think it isn't a "plain object"
159+
// to get around this, we do a deep clone of the object
160+
if (inIframe() && !isPlainObject(x))
161+
x = $.extend(true, {}, x)
162+
158163
// if no plot exists yet, create one with a particular configuration
159164
if (!instance.plotly) {
160165

161-
var plot = Plotly.plot(graphDiv, x);
166+
var plot = Plotly.plot(graphDiv, {...x});
162167
instance.plotly = true;
163168
instance.autosize = x.layout.autosize || true;
164169
instance.width = x.layout.width;
@@ -832,6 +837,10 @@ function isPlainObject(obj) {
832837
);
833838
}
834839

840+
function inIframe() {
841+
return window && window.self !== window.top;
842+
}
843+
835844
function subsetArrayAttrs(obj, indices) {
836845
var newObj = {};
837846
Object.keys(obj).forEach(function(k) {

0 commit comments

Comments
 (0)