chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<!--[metadata]
|
||||
title = "Table with editable flags"
|
||||
tags = ["Tables", "Server"]
|
||||
include_in_manifest = false
|
||||
-->
|
||||
|
||||
## Table grid with flags
|
||||
|
||||
Starts a local server with a table containing an index column and a boolean flag column.
|
||||
The flag column is marked with Arrow metadata so the viewer's card/grid view can toggle flags
|
||||
and persist them back to the server.
|
||||
|
||||
The flag column remains part of the table data. Its current boolean value controls the flag icon shown on each grid card. Clicking the icon immediately updates the visible table state and sends an upsert back to the server containing the row's table-index value plus the new flag value. The `rerun:is_table_index` column is required so the server knows which row to update.
|
||||
|
||||
<!-- TODO(#12745): this is still experimental -->
|
||||
Enable `Settings > Experimental > Table cards and blueprints` in the viewer, then open the
|
||||
printed URL.
|
||||
|
||||
Flagging works on regular tables, but does **not** yet work on the segment tables of datasets:
|
||||
segment tables have no write operations yet, so flag changes cannot be persisted back to the server.
|
||||
|
||||
## Run the code
|
||||
|
||||
```bash
|
||||
pip install -e examples/python/table_grid_with_flags
|
||||
table_grid_with_flags
|
||||
```
|
||||
|
||||
or via pixi/uv:
|
||||
|
||||
```bash
|
||||
pixi run py-build && pixi run uv run examples/python/table_grid_with_flags/table_grid_with_flags.py
|
||||
```
|
||||
@@ -0,0 +1,12 @@
|
||||
[project]
|
||||
name = "table_grid_with_flags"
|
||||
version = "0.1.0"
|
||||
readme = "README.md"
|
||||
dependencies = ["pyarrow", "rerun-sdk"]
|
||||
|
||||
[project.scripts]
|
||||
table_grid_with_flags = "table_grid_with_flags:main"
|
||||
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
@@ -0,0 +1,75 @@
|
||||
"""
|
||||
Experimental table grid with flag toggles.
|
||||
|
||||
Demonstrates the card/grid table layout and per-row flag annotations on a
|
||||
remote table.
|
||||
|
||||
**TODO(#12745): This feature is experimental.** Enable it in the viewer under
|
||||
Settings > Experimental > Table cards and blueprints.
|
||||
|
||||
The flag column is configured via Arrow field metadata
|
||||
(`rerun:is_flag_column = "true"`). The Viewer treats that boolean column
|
||||
as the per-row flag state: each value drives the flag icon on the grid card,
|
||||
and clicking the icon updates the visible table state and upserts the new
|
||||
boolean value back to the server. The table must also have a
|
||||
`rerun:is_table_index` column so the upsert can target the row to update.
|
||||
|
||||
Usage:
|
||||
table_grid_with_flags
|
||||
|
||||
# In a separate terminal, open the viewer with the URL printed by the script:
|
||||
rerun <url>
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
|
||||
import pyarrow as pa
|
||||
|
||||
import rerun as rr
|
||||
from rerun.server import Server
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Create an experimental table grid with flag toggles.")
|
||||
parser.add_argument("--port", type=int, default=None, help="Port for the local Rerun server.")
|
||||
args = parser.parse_args()
|
||||
|
||||
schema = pa.schema([
|
||||
pa.field(
|
||||
"id",
|
||||
pa.int64(),
|
||||
metadata={rr.SORBET_IS_TABLE_INDEX: "true"},
|
||||
),
|
||||
pa.field("name", pa.utf8()),
|
||||
pa.field("category", pa.utf8()),
|
||||
pa.field("score", pa.float64()),
|
||||
pa.field(
|
||||
"flagged",
|
||||
pa.bool_(),
|
||||
metadata={"rerun:is_flag_column": "true"},
|
||||
),
|
||||
])
|
||||
|
||||
data = {
|
||||
"id": [1, 2, 3, 4, 5],
|
||||
"name": ["Alice", "Bob", "Charlie", "Diana", "Eve"],
|
||||
"category": ["robotics", "vision", "robotics", "spatial", "vision"],
|
||||
"score": [95.0, 82.5, 91.0, 88.0, 76.5],
|
||||
"flagged": [False, False, False, False, False],
|
||||
}
|
||||
|
||||
with Server(port=args.port) as srv:
|
||||
client = srv.client()
|
||||
table = client.create_table("flag_demo", schema)
|
||||
table.append(**data)
|
||||
|
||||
url = f"{srv.url()}/entry/{table.id}"
|
||||
print(f"Open the viewer with:\n rerun {url}")
|
||||
|
||||
input("Press Enter to stop the server…")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user