diff --git a/js/src/output.ts b/js/src/output.ts index 1383eb1..4486dcf 100644 --- a/js/src/output.ts +++ b/js/src/output.ts @@ -252,6 +252,17 @@ $(document).on("shiny:disconnected", () => { manager.clear_state(); }); +// When in filling layout, some widgets (specifically, altair) incorrectly think their +// height is 0 after it's shown, hidden, then shown again. As a workaround, trigger a +// resize event when a tab is shown. TODO: This covers the 95% use case, but it's +// definitely not an ideal way to handle this situation. A more robust solution would +// use IntersectionObserver to detect when the widget becomes visible. Or better yet, +// we'd get altair to handle this situation better. +// https://github.com/posit-dev/py-shinywidgets/issues/172 +document.addEventListener('shown.bs.tab', event => { + window.dispatchEvent(new Event('resize')); +}) + // Our version of https://github.com/jupyter-widgets/widget-cookiecutter/blob/9694718/%7B%7Bcookiecutter.github_project_name%7D%7D/js/lib/extension.js#L8 function setBaseURL(x: string = '') { const base_url = document.querySelector('body').getAttribute('data-base-url'); diff --git a/shinywidgets/static/output.js b/shinywidgets/static/output.js index db65d40..3ac9da4 100644 --- a/shinywidgets/static/output.js +++ b/shinywidgets/static/output.js @@ -36,7 +36,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \***********************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _jupyter_widgets_html_manager__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @jupyter-widgets/html-manager */ \"@jupyter-widgets/html-manager\");\n/* harmony import */ var _jupyter_widgets_html_manager__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_jupyter_widgets_html_manager__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _comm__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./comm */ \"./src/comm.ts\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils */ \"./src/utils.ts\");\nvar _a;\n\n\n\n/******************************************************************************\n * Define a custom HTMLManager for use with Shiny\n ******************************************************************************/\nclass OutputManager extends _jupyter_widgets_html_manager__WEBPACK_IMPORTED_MODULE_0__.HTMLManager {\n // In a soon-to-be-released version of @jupyter-widgets/html-manager,\n // display_view()'s first \"dummy\" argument will be removed... this shim simply\n // makes it so that our manager can work with either version\n // https://github.com/jupyter-widgets/ipywidgets/commit/159bbe4#diff-45c126b24c3c43d2cee5313364805c025e911c4721d45ff8a68356a215bfb6c8R42-R43\n async display_view(view, options) {\n const n_args = super.display_view.length;\n if (n_args === 3) {\n return super.display_view({}, view, options);\n }\n else {\n // @ts-ignore\n return super.display_view(view, options);\n }\n }\n}\n// Define our own custom module loader for Shiny\nconst shinyRequireLoader = async function (moduleName, moduleVersion) {\n // shiny provides require.js and also sets `define.amd=false` to prevent