Skip to content

Commit 468d758

Browse files
authored
Docs: Update howto/notebook + READMEs (#6782)
1 parent a25ac64 commit 468d758

File tree

2 files changed

+54
-38
lines changed

2 files changed

+54
-38
lines changed

docs/content/howto/notebook.md

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ Rerun has been tested with:
1414
- [VSCode](https://code.visualstudio.com/blogs/2021/08/05/notebooks)
1515
- [Google Colab](https://colab.research.google.com/)
1616

17-
## Basic concept
17+
To begin, install the `rerun-sdk` package with the `notebook` extra:
18+
```sh
19+
pip install rerun-sdk[notebook]
20+
```
1821

19-
When using the Rerun logging APIs, by default, the logged messages are buffered in-memory until
20-
you send them to a sink such as via `rr.connect()` or `rr.save()`. When using Rerun in a notebook,
21-
rather than using the other sinks, you have the option to use a helper method: [`rr.notebook_show()`](https://ref.rerun.io/docs/python/stable/common/initialization_functions/#rerun.notebook_show).
22-
This method takes any buffered messages and converts them into an HTML snipped including
23-
the inlined data along with an instance of the Viewer in an iframe.
22+
This installs both [rerun-sdk](https://pypi.org/project/rerun-sdk/) and [rerun-notebook](https://pypi.org/project/rerun-notebook/).
2423

2524
## The APIs
2625

27-
In order to output the current recording data to a notebook cell, call:
28-
[`rr.notebook_show()`](https://ref.rerun.io/docs/python/stable/common/initialization_functions/#rerun.notebook_show).
26+
When using the Rerun logging APIs, by default, the logged messages are buffered in-memory until
27+
you send them to a sink such as via `rr.connect()` or `rr.save()`.
28+
29+
When using Rerun in a notebook, rather than using the other sinks, you have the option to use [`rr.notebook_show()`](https://ref.rerun.io/docs/python/stable/common/initialization_functions/#rerun.notebook_show). This method embeds the [web viewer](./embed-rerun-viewer.md) using the IPython `display` mechanism in the cell output, and sends the current recording data to it.
30+
31+
Once the viewer is open, any subsequent `rr.log()` calls will send their data directly to the viewer,
32+
without any intermediate buffering.
2933

3034
For example:
3135

@@ -54,19 +58,15 @@ rr.notebook_show()
5458
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/notebook_example/e47920b7ca7988aba305d73b2aea2da7b81c93e3/1200w.png">
5559
</picture>
5660

57-
This is similar to calling `rr.connect()` or `rr.save()` in that it configures the Rerun SDK to use
58-
this memory buffer as the sink for future logging calls.
59-
60-
Note that the output cell is essentially a fixed snapshot of the
61-
current state of the recording at the time that `notebook_show()` is called. Rerun does not yet
62-
support live incremental streaming from the Jupyter kernel into the embedded viewer.
61+
This is similar to calling `rr.connect()` or `rr.serve()` in that it configures the Rerun SDK to send data to a viewer instance.
6362

64-
Messages will continue to be buffered incrementally, and each call to `notebook_show()` will
65-
display all messages that have been logged since the last call to `rr.init()`.
63+
Note that the call to `rr.notebook_show()` drains the recording of its data. This means that any subsequent calls to `rr.notebook_show()`
64+
will not result in the same data being displayed, because it has already been removed from the recording.
65+
Support for this is tracked in [#6612](https://github.com/rerun-io/rerun/issues/6612).
6666

67-
If you wish to clear the current recording, you can call `rr.init()` again.
67+
If you wish to start a new recording, you can call `rr.init()` again.
6868

69-
The `notebook_show()` method also takes optional arguments for specifying the width and height of the IFrame. For example:
69+
The `notebook_show()` method also takes optional arguments for specifying the width and height of the viewer. For example:
7070

7171
```python
7272
rr.notebook_show(width=400, height=400)
@@ -90,7 +90,7 @@ blueprint = rrb.Blueprint(
9090
rr.notebook_show(blueprint=blueprint)
9191
```
9292

93-
Because blueprint types implement `_repr_html_`, you can also just end any cell with a blueprint
93+
Because blueprint types implement `_ipython_display_`, you can also just end any cell with a blueprint
9494
object, and it will call `notebook_show()` behind the scenes.
9595

9696
```python
@@ -121,6 +121,33 @@ rrb.Vertical(
121121
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/notebook_blueprint_example/eb0663a9a8a0de8276390667a774acc1bc86148e/1200w.png">
122122
</picture>
123123

124+
## Streaming data
125+
126+
The notebook integration supports streaming data to the viewer during cell execution.
127+
128+
You can call `rr.notebook_show()` at any point after calling `rr.init()`, and any
129+
`rr.log()` calls will be sent to the viewer in real-time.
130+
131+
```python
132+
import math
133+
from time import sleep
134+
135+
import numpy as np
136+
import rerun as rr
137+
from rerun.utilities import build_color_grid
138+
139+
rr.init("rerun_example_notebook")
140+
rr.notebook_show()
141+
142+
STEPS = 100
143+
twists = math.pi * np.sin(np.linspace(0, math.tau, STEPS)) / 4
144+
for t in range(STEPS):
145+
sleep(0.05) # delay to simulate a long-running computation
146+
rr.set_time_sequence("step", t)
147+
cube = build_color_grid(10, 10, 10, twist=twists[t])
148+
rr.log("cube", rr.Points3D(cube.positions, colors=cube.colors, radii=0.5))
149+
```
150+
124151
## Some working examples
125152

126153
To experiment with notebooks yourself, there are a few options.
@@ -146,27 +173,11 @@ We also host a copy of the notebook in [Google Colab](https://colab.research.goo
146173
Note that if you copy and run the notebook yourself, the first Cell installs Rerun into the Colab environment.
147174
After running this cell you will need to restart the Runtime for the Rerun package to show up successfully.
148175

149-
## Sharing your notebook
150-
151-
Because the Rerun Viewer in the notebook is just an embedded HTML snippet it also works with
152-
tools like nbconvert.
153-
154-
You can convert the notebook to HTML using the following command:
155-
156-
```bash
157-
$ jupyter nbconvert --to=html --ExecutePreprocessor.enabled=True examples/python/notebook/cube.ipynb
158-
```
159-
160-
This will create a new file `cube.html` that can be hosted on any static web server.
161-
162-
[Example cube.html](https://static.rerun.io/93d3f93e0951b2e2fedcf70f71014a3b3a5e8ef6_cube.html)
163-
164176
## Limitations
165177

166-
Although convenient, the approach of fully inlining an RRD file as an HTML snippet has some drawbacks. In particular,
167-
it is not suited to large RRD files. The RRD file is embedded as a base64 encoded string which can
168-
result in a very large HTML file. This can cause problems in some browsers. If you want to share large datasets,
169-
we recommend using the `save()` API to create a separate file and hosting it as a separate standalone asset.
178+
Browsers have limitations in the amount of memory usable by a single tab. If you are working with large datasets,
179+
you may run into browser tab crashes due to out-of-memory errors.
180+
If you encounter the issue, you can try to use the `save()` API to save the data to a file and share it as a standalone asset.
170181

171182
## Future work
172183

rerun_py/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ The Python module is called `rerun`, while the package published on PyPI is `rer
1717

1818
For other SDK languages see [Installing Rerun](https://www.rerun.io/docs/getting-started/installing-viewer).
1919

20+
We also provide a [Jupyter widget](https://pypi.org/project/rerun-notebook/) for interactive data visualization in Jupyter notebooks:
21+
```sh
22+
pip3 install rerun-sdk[notebook]
23+
```
24+
2025
## Example
2126
```py
2227
import rerun as rr

0 commit comments

Comments
 (0)