Skip to content

Commit 08c32fe

Browse files
committed
More generally ensure Shiny.OutputBinding.renderValue() doesn't produce multiple widget views on a given element
1 parent 31410ef commit 08c32fe

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

js/src/output.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ class IPyWidgetOutput extends Shiny.OutputBinding {
103103
const view = await manager.create_view(model, {});
104104
await manager.display_view(view, {el: el});
105105

106+
// Don't allow more than one .lmWidget container, which can happen
107+
// when the view is displayed more than once
108+
// N.B. It's probably better to get view(s) from m.views and .remove() them,
109+
// but empirically, this seems to work better
110+
while (el.childNodes.length > 1) {
111+
el.removeChild(el.childNodes[0]);
112+
}
113+
106114
// The ipywidgets container (.lmWidget)
107115
const lmWidget = el.children[0] as HTMLElement;
108116

0 commit comments

Comments
 (0)