Skip to content

Commit a774c59

Browse files
Jeffrey Shenchschan
Jeffrey Shen
authored andcommitted
Support renderValue within iframe
1 parent a4b1581 commit a774c59

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

inst/htmlwidgets/plotly.js

+16
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ HTMLWidgets.widget({
156156
}
157157
}
158158

159+
// remove "sendDataToCloud", unless user has specified they want it
160+
x.config = x.config || {};
161+
if (!x.config.cloud) {
162+
x.config.modeBarButtonsToRemove = x.config.modeBarButtonsToRemove || [];
163+
x.config.modeBarButtonsToRemove.push("sendDataToCloud");
164+
}
165+
166+
// if the object was passed in from another window, plotly will falsely think it isn't a "plain object"
167+
// to get around this, we have to create a deep copy of the object
168+
if (inIframe() && !isPlainObject(x))
169+
x = JSON.parse(JSON.stringify(x))
170+
159171
// if no plot exists yet, create one with a particular configuration
160172
if (!instance.plotly) {
161173

@@ -876,6 +888,10 @@ function isPlainObject(obj) {
876888
);
877889
}
878890

891+
function inIframe() {
892+
return window && window.self !== window.top;
893+
}
894+
879895
function subsetArrayAttrs(obj, indices) {
880896
var newObj = {};
881897
Object.keys(obj).forEach(function(k) {

0 commit comments

Comments
 (0)