Skip to content

Commit 5c01af7

Browse files
committed
Close #159. Combine libembed and output scripts into single dependency to avoid Quarto dependency ordering bug
1 parent 1c97ac3 commit 5c01af7

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to shinywidgets will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [UNRELEASED]
9+
10+
* Fixed an issue where widgets would sometimes fail to render in a Quarto document. (#159)
11+
812
## [0.3.3] - 2024-08-13
913

1014
* Fixed a bug with receiving binary data on the frontend, which gets [quak](https://github.com/manzt/quak) and [mosaic-widget](https://idl.uw.edu/mosaic/jupyter/) working with `@render_widget`. (#152)

shinywidgets/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
__author__ = """Carson Sievert"""
44
__email__ = "[email protected]"
5-
__version__ = "0.3.3"
5+
__version__ = "0.3.3.9000"
66

77
from ._as_widget import as_widget
88
from ._dependencies import bokeh_dependency

shinywidgets/_dependencies.py

+22-27
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,33 @@
2222

2323

2424
# TODO: scripts/static_download.R should produce/update these
25-
def libembed_dependency() -> List[HTMLDependency]:
26-
return [
27-
# Jupyter Notebook/Lab both come "preloaded" with several @jupyter-widgets packages
28-
# (i.e., base, controls, output), all of which are bundled into this extension.js file
29-
# provided by the widgetsnbextension package, which is a dependency of ipywidgets.
30-
# https://github.com/nteract/nes/tree/master/portable-widgets
31-
# https://github.com/jupyter-widgets/ipywidgets/blob/88cec8/packages/html-manager/src/htmlmanager.ts#L115-L120
32-
#
33-
# Unfortunately, I don't think there is a good way for us to "pre-bundle" these dependencies
34-
# since they could change depending on the version of ipywidgets (and ipywidgets itself
35-
# doesn't include these dependencies in such a way that require("@jupyter-widget/base") would
36-
# work robustly when used in other 3rd party widgets). Moreover, I don't think we can simply
37-
# have @jupyter-widget/base point to https://unpkg.com/@jupyter-widgets/base@__version__/lib/index.js
38-
# (or a local version of this) since it appears the lib entry points aren't usable in the browser.
39-
#
40-
# All this is to say that I think we are stuck with this mega 3.5MB file that contains all of the
41-
# stuff we need to render widgets outside of the notebook.
42-
HTMLDependency(
43-
name="ipywidget-libembed-amd",
44-
version=parse_version_safely(__html_manager_version__),
45-
source={"package": "shinywidgets", "subdir": "static"},
46-
script={"src": "libembed-amd.js"},
47-
),
48-
]
49-
50-
5125
def output_binding_dependency() -> HTMLDependency:
26+
# Jupyter Notebook/Lab both come "preloaded" with several @jupyter-widgets packages
27+
# (i.e., base, controls, output), all of which are bundled into this extension.js file
28+
# provided by the widgetsnbextension package, which is a dependency of ipywidgets.
29+
# https://github.com/nteract/nes/tree/master/portable-widgets
30+
# https://github.com/jupyter-widgets/ipywidgets/blob/88cec8/packages/html-manager/src/htmlmanager.ts#L115-L120
31+
#
32+
# Unfortunately, I don't think there is a good way for us to "pre-bundle" these dependencies
33+
# since they could change depending on the version of ipywidgets (and ipywidgets itself
34+
# doesn't include these dependencies in such a way that require("@jupyter-widget/base") would
35+
# work robustly when used in other 3rd party widgets). Moreover, I don't think we can simply
36+
# have @jupyter-widget/base point to https://unpkg.com/@jupyter-widgets/base@__version__/lib/index.js
37+
# (or a local version of this) since it appears the lib entry points aren't usable in the browser.
38+
#
39+
# All this is to say that I think we are stuck with this mega 3.5MB file that contains all of the
40+
# stuff we need to render widgets outside of the notebook.
5241
return HTMLDependency(
5342
name="ipywidget-output-binding",
5443
version=__version__,
5544
source={"package": "shinywidgets", "subdir": "static"},
56-
script={"src": "output.js"},
45+
script=[
46+
{"src": "libembed-amd.js"},
47+
# Bundle our output.js in the same dependency as libembded since Quarto
48+
# has a bug where it doesn't renders dependencies in the order they are defined
49+
# (i.e., this way we can ensure the output.js script always comes after the libembed-amd.js script tag)
50+
{"src": "output.js"},
51+
],
5752
stylesheet={"href": "shinywidgets.css"},
5853
)
5954

shinywidgets/_output_widget.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from shiny.ui.fill import as_fill_item, as_fillable_container
99

1010
from ._cdn import SHINYWIDGETS_CDN, SHINYWIDGETS_CDN_ONLY
11-
from ._dependencies import libembed_dependency, output_binding_dependency
11+
from ._dependencies import output_binding_dependency
1212

1313
__all__ = ("output_widget",)
1414

@@ -23,7 +23,6 @@ def output_widget(
2323
) -> Tag:
2424
id = resolve_id(id)
2525
res = tags.div(
26-
*libembed_dependency(),
2726
output_binding_dependency(),
2827
head_content(
2928
tags.script(

0 commit comments

Comments
 (0)