Library Interface
This library exposes a single function embed
that renders a notebook into a given DOM node and returns an interface for further interaction with the notebook:
WolframNotebookEmbedder.embed(source, domNode, attributes)
source
:- a string with a cloud object URL of the notebook to embed, e.g.
'https://www.wolframcloud.com/obj/4beadfbb-84dd-4b26-87b6-bcd30b9abd65'
or'https://www.wolframcloud.com/obj/myusername/myfolder/mynotebook.nb'
, or - an object with the following properties:
cloudBase
(optional): a string denoting the cloud base to use (defaulting tohttps://www.wolframcloud.com
)expr
(a string containing aNotebook[...]
expression in InputForm) orurl
(a URL to fetch a notebook file from) orpath
(the path of a cloud object in the specifiedcloudBase
)
- a string with a cloud object URL of the notebook to embed, e.g.
domNode
: a DOM node in which to render the notebook, e.g. obtained bydocument.getElementById('myContainer')
attributes
: a JavaScript object with attributes
A source
string such as 'https://www.wolframcloud.com/obj/myusername/myfolder/mynotebook.nb'
is equivalent to an object such as
{"cloudBase": "https://www.wolframcloud.com", "path": "myusername/myfolder/mynotebook.nb"}
where the cloudBase
and the path
are determined based on the given string.
The following attributes can be given:
width
: width of the notebook in pixels; a value ofnull
(the default) makes the notebook adapt to the width of the container nodemaxHeight
: maximum height of the notebook in pixels; a value ofInfinity
(the default) allows the notebook to grow infinitely; a value ofnull
makes the notebook adapt to the height of the container nodeshowBorder
: whether to show a border around the notebook; the defaultnull
will take into account a corresponding option of the embedded cloud objectallowInteract
: whether to enable interactivity in the notebook, which might use the server-side Wolfram Engine for computations; even if this is set totrue
(the default), thePermissions
of the cloud notebook must also includeAll -> {"Read", "Interact"}
for interactions to actually workshowRenderProgress
: whether to show the render progress indicator at the top of the notebook during the initial loading phase (see Notebook Loading Phases for more information); the default istrue
useShadowDOM
(experimental): whether to use a shadow DOM container for the notebook; the default isfalse
(but might change in a future release after 0.2.x)
If the notebook exceeds the given width or height, scrollbars are introduced in that dimension. The default dimensions (width: null
, maxHeight: Infinity
) let the notebook adapt to the container node's width (line-wrapping as necessary) and make the container node grow vertically as necessary, so there will not be a vertical scrollbar, and there will only be a horizontal scrollbar if the notebook's contents are inherently wider than the available width (e.g. a graphic with a fixed size). In the case of maxHeight: null
, the notebook's background will fill out the whole container node even if the notebook content is smaller.
The embedded notebook needs to be public (i.e. with Permissions of at least All->"Read"
). For interactivity to work, the "Interact"
permission is needed.
Notebooks on Wolfram Enterprise Private Cloud (EPC) can be embedded as well, as long as they are public. Just use the cloud object URL pointing to your EPC as the notebookURL
.
The function embed
returns a Promise
resolving to an object with various methods to control the notebook, e.g.:
setAttributes(options)
: changes embedding attributes (except forallowInteract
anduseShadowDOM
, which cannot be changed dynamically)detach()
: call this function when the embedded notebook is no longer needed, e.g. because the node it is embedded in disappearsaddEventListener(eventName, callback)
: registers an event listenerremoveEventListener(eventName, callback)
: unregisters an event listener- many other notebook-related functions, e.g.
getDimensions()
,getCells()
,evaluateExpression(expr)
See the notebook API documentation for more details about these methods.
If something goes wrong while loading the notebook (e.g. because there is no notebook at the given notebookURL
), the returned promise is rejected.