Cell helpers
Cell is the immutable authored-cell record. ojs, js, md, and html
create the modes used most often from Python.
import observablejs as obs
notebook = obs.Notebook(
obs.md("# Report", key="title"),
obs.ojs("total = rows.length", key="total", display=False),
variables={"rows": [{"x": 1}, {"x": 2}]},
)
Cell
Cell(
source,
mode="ojs",
key=None,
display=True,
raw=False,
id=None,
pinned=False,
output=None,
notebookkit_attrs={},
)
| Argument | Contract |
|---|---|
source | Cell source string. |
mode | js, ts, ojs, md, html, tex, dot, sql, node, python, or r. |
key | Nonempty portable public identity. Serialized as data-pyobservablejs-key. |
display | False emits the Notebook Kit hidden attribute. |
raw | True preserves indentation and surrounding newlines. |
id | Optional unique positive Notebook Kit serialization id through JavaScript's safe integer maximum. |
pinned | Marks source for display when the notebook enables pinned source. |
output | Notebook Kit output metadata. |
notebookkit_attrs | Typed mode metadata for database, format, or since. |
With raw=False, construction dedents the source and strips surrounding
newlines. Invalid source or id types raise TypeError. Unsupported modes,
empty keys, unsafe ids, and collisions between first-class fields and
notebookkit_attrs raise ValueError.
Helper functions
ojs(source, *, key=None, display=True, raw=False, id=None, pinned=False, output=None, notebookkit_attrs=None) -> Cell
js(source, *, key=None, display=True, raw=False, id=None, pinned=False, output=None, notebookkit_attrs=None) -> Cell
md(source, *, key=None, display=True, raw=False, id=None, pinned=False, output=None, notebookkit_attrs=None) -> Cell
html(source, *, key=None, display=True, raw=False, id=None, pinned=False, output=None, notebookkit_attrs=None) -> Cell
The helper fixes the corresponding mode and forwards every other argument to
Cell. Observable variable names come from source code. Cell selection uses
the public key.