Skip to content

Commit c96725f

Browse files
grtlremilk
authored andcommitted
Example showcasing send_table from notebooks (#9522)
Also removes a forgotten `re_log::info!` statement from development.
1 parent 7e67324 commit c96725f

File tree

2 files changed

+249
-1
lines changed

2 files changed

+249
-1
lines changed

crates/viewer/re_viewer/src/web.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,6 @@ pub fn set_email(email: String) {
909909
// This is required to send bytes around in the notebook.
910910
// If you ever change this, you also need to adapt `notebook.py` too.
911911
pub fn from_arrow_encoded(data: &RecordBatch) -> Result<TableMsg, Box<dyn std::error::Error>> {
912-
re_log::info!("{:?}", data);
913912
let mut metadata = data.schema().metadata().clone();
914913
let id = metadata
915914
.remove("__table_id")
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "85c477c3-5f26-4294-a2ea-4042a0c38b7f",
6+
"metadata": {},
7+
"source": [
8+
"### How to run\n",
9+
"\n",
10+
"```sh\n",
11+
"# pixi run py-build-examples\n",
12+
"# pixi run -e examples py-build-notebook\n",
13+
"# pixi run -e examples jupyter notebook examples/python/notebook/send_table.ipynb\n",
14+
"```"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 1,
20+
"id": "e5789224-afa8-4250-9eae-2ca570d46088",
21+
"metadata": {},
22+
"outputs": [],
23+
"source": [
24+
"from __future__ import annotations\n",
25+
"\n",
26+
"import os\n",
27+
"\n",
28+
"os.environ[\"RERUN_NOTEBOOK_ASSET\"] = \"inline\""
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 5,
34+
"id": "c993d2ab-5bbb-4af0-89a5-1c370b7b9523",
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"import rerun as rr\n",
39+
"\n",
40+
"import pyarrow as pa\n",
41+
"import pandas as pd"
42+
]
43+
},
44+
{
45+
"cell_type": "markdown",
46+
"id": "e317e818-4a96-4c63-a9a0-cce25073b2e5",
47+
"metadata": {},
48+
"source": [
49+
"### Send a basic table"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 3,
55+
"id": "aea716a4-164c-436f-9b6a-ca6f171214b5",
56+
"metadata": {},
57+
"outputs": [
58+
{
59+
"data": {
60+
"application/vnd.jupyter.widget-view+json": {
61+
"model_id": "bd5a1609428f42d689dbde5a2b79d0db",
62+
"version_major": 2,
63+
"version_minor": 1
64+
},
65+
"text/plain": [
66+
"Viewer()"
67+
]
68+
},
69+
"metadata": {},
70+
"output_type": "display_data"
71+
}
72+
],
73+
"source": [
74+
"viewer = rr.notebook.Viewer(width=1024, height=700)\n",
75+
"viewer.display()\n",
76+
"viewer.send_table(\n",
77+
" \"Hello from Notebook\",\n",
78+
" pa.RecordBatch.from_pydict({\"Column A\": [1, 2, 3], \"Column B\": [\"https://www.rerun.io\", \"Hello\", \"World\"]}),\n",
79+
")"
80+
]
81+
},
82+
{
83+
"cell_type": "markdown",
84+
"id": "59ebc9cb-cb8f-47e9-9beb-a9ff96a7ca17",
85+
"metadata": {},
86+
"source": [
87+
"### Send a Pandas dataframe"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": 6,
93+
"id": "e15fcb31-4e74-47f9-9eba-b6bcdc545c2b",
94+
"metadata": {},
95+
"outputs": [
96+
{
97+
"data": {
98+
"text/html": [
99+
"<div>\n",
100+
"<style scoped>\n",
101+
" .dataframe tbody tr th:only-of-type {\n",
102+
" vertical-align: middle;\n",
103+
" }\n",
104+
"\n",
105+
" .dataframe tbody tr th {\n",
106+
" vertical-align: top;\n",
107+
" }\n",
108+
"\n",
109+
" .dataframe thead th {\n",
110+
" text-align: right;\n",
111+
" }\n",
112+
"</style>\n",
113+
"<table border=\"1\" class=\"dataframe\">\n",
114+
" <thead>\n",
115+
" <tr style=\"text-align: right;\">\n",
116+
" <th></th>\n",
117+
" <th>A</th>\n",
118+
" <th>B</th>\n",
119+
" <th>C</th>\n",
120+
" <th>D</th>\n",
121+
" </tr>\n",
122+
" </thead>\n",
123+
" <tbody>\n",
124+
" <tr>\n",
125+
" <th>2013-01-01</th>\n",
126+
" <td>0.823557</td>\n",
127+
" <td>-0.290076</td>\n",
128+
" <td>0.238599</td>\n",
129+
" <td>-0.629761</td>\n",
130+
" </tr>\n",
131+
" <tr>\n",
132+
" <th>2013-01-02</th>\n",
133+
" <td>-0.520894</td>\n",
134+
" <td>-0.817653</td>\n",
135+
" <td>-0.169291</td>\n",
136+
" <td>-0.506261</td>\n",
137+
" </tr>\n",
138+
" <tr>\n",
139+
" <th>2013-01-03</th>\n",
140+
" <td>-0.002897</td>\n",
141+
" <td>0.752245</td>\n",
142+
" <td>-0.613818</td>\n",
143+
" <td>1.111361</td>\n",
144+
" </tr>\n",
145+
" <tr>\n",
146+
" <th>2013-01-04</th>\n",
147+
" <td>0.938248</td>\n",
148+
" <td>-1.109515</td>\n",
149+
" <td>0.536320</td>\n",
150+
" <td>-1.075220</td>\n",
151+
" </tr>\n",
152+
" <tr>\n",
153+
" <th>2013-01-05</th>\n",
154+
" <td>0.033130</td>\n",
155+
" <td>0.771321</td>\n",
156+
" <td>0.310634</td>\n",
157+
" <td>-0.595946</td>\n",
158+
" </tr>\n",
159+
" <tr>\n",
160+
" <th>2013-01-06</th>\n",
161+
" <td>1.205717</td>\n",
162+
" <td>-2.282729</td>\n",
163+
" <td>1.290203</td>\n",
164+
" <td>0.592006</td>\n",
165+
" </tr>\n",
166+
" </tbody>\n",
167+
"</table>\n",
168+
"</div>"
169+
],
170+
"text/plain": [
171+
" A B C D\n",
172+
"2013-01-01 0.823557 -0.290076 0.238599 -0.629761\n",
173+
"2013-01-02 -0.520894 -0.817653 -0.169291 -0.506261\n",
174+
"2013-01-03 -0.002897 0.752245 -0.613818 1.111361\n",
175+
"2013-01-04 0.938248 -1.109515 0.536320 -1.075220\n",
176+
"2013-01-05 0.033130 0.771321 0.310634 -0.595946\n",
177+
"2013-01-06 1.205717 -2.282729 1.290203 0.592006"
178+
]
179+
},
180+
"execution_count": 6,
181+
"metadata": {},
182+
"output_type": "execute_result"
183+
}
184+
],
185+
"source": [
186+
"dates = pd.date_range(\"20130101\", periods=6)\n",
187+
"df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list(\"ABCD\"))\n",
188+
"df_reset = df.reset_index().rename(columns={'index': 'date'})\n",
189+
"df"
190+
]
191+
},
192+
{
193+
"cell_type": "code",
194+
"execution_count": 7,
195+
"id": "837e06ba-ad72-4dff-a6f4-5e7e211a137d",
196+
"metadata": {},
197+
"outputs": [
198+
{
199+
"data": {
200+
"application/vnd.jupyter.widget-view+json": {
201+
"model_id": "aa0fb7b7b5884f3fa7f7653b2f81bb39",
202+
"version_major": 2,
203+
"version_minor": 1
204+
},
205+
"text/plain": [
206+
"Viewer()"
207+
]
208+
},
209+
"metadata": {},
210+
"output_type": "display_data"
211+
}
212+
],
213+
"source": [
214+
"viewer = rr.notebook.Viewer(width=1024, height=700)\n",
215+
"viewer.display()\n",
216+
"viewer.send_table(\"Hello from Pandas\", pa.RecordBatch.from_pandas(df))"
217+
]
218+
},
219+
{
220+
"cell_type": "code",
221+
"execution_count": null,
222+
"id": "7de877bf-f3ba-4f73-867a-1dd7930a2063",
223+
"metadata": {},
224+
"outputs": [],
225+
"source": []
226+
}
227+
],
228+
"metadata": {
229+
"kernelspec": {
230+
"display_name": "Python 3 (ipykernel)",
231+
"language": "python",
232+
"name": "python3"
233+
},
234+
"language_info": {
235+
"codemirror_mode": {
236+
"name": "ipython",
237+
"version": 3
238+
},
239+
"file_extension": ".py",
240+
"mimetype": "text/x-python",
241+
"name": "python",
242+
"nbconvert_exporter": "python",
243+
"pygments_lexer": "ipython3",
244+
"version": "3.11.10"
245+
}
246+
},
247+
"nbformat": 4,
248+
"nbformat_minor": 5
249+
}

0 commit comments

Comments
 (0)