Skip to content

Commit 8881fb1

Browse files
committed
support panel states
1 parent 8c10128 commit 8881fb1

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

Diff for: backend/gradio_rerun/rerun.py

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(
4747
elem_id: str | None = None,
4848
elem_classes: list[str] | str | None = None,
4949
render: bool = True,
50+
panel_states: dict[str, Any] | None = None,
5051
):
5152
"""
5253
Parameters:
@@ -63,9 +64,11 @@ def __init__(
6364
elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
6465
elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
6566
render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
67+
panel_states: Force viewer panels to a specific state. Any panels set cannot be toggled by the user in the viewer. Panel names are "top", "blueprint", "selection", and "time". States are "hidden", "collapsed", and "expanded".
6668
"""
6769
self.height = height
6870
self.streaming = streaming
71+
self.panel_states = panel_states
6972
super().__init__(
7073
label=label,
7174
every=every,
@@ -81,6 +84,11 @@ def __init__(
8184
value=value,
8285
)
8386

87+
def get_config(self):
88+
config = super().get_config()
89+
config["panel_states"] = self.panel_states
90+
return config
91+
8492
def preprocess(self, payload: RerunData | None) -> RerunData | None:
8593
"""
8694
This component does not accept input.

Diff for: demo/app.py

+5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ def cleanup_cube_rrds(pending_cleanup):
133133
with gr.Row():
134134
viewer = Rerun(
135135
streaming=True,
136+
panel_states={
137+
"time": "hidden",
138+
"blueprint": "hidden",
139+
"selection": "hidden",
140+
},
136141
)
137142

138143
stream_blur.click(streaming_repeated_blur, inputs=[img], outputs=[viewer])

Diff for: frontend/Index.svelte

+19-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import "./app.css";
99
import type { Gradio } from "@gradio/utils";
1010
11-
import { WebViewer } from "@rerun-io/web-viewer";
11+
import { WebViewer, type Panel, type PanelState } from "@rerun-io/web-viewer";
1212
import { onMount } from "svelte";
1313
1414
import { Block } from "@gradio/atoms";
@@ -32,6 +32,7 @@
3232
export let loading_status: LoadingStatus;
3333
export let interactive: boolean;
3434
export let streaming: boolean;
35+
export let panel_states: { [K in Panel]: PanelState } | null = null;
3536
3637
let old_value: null | BinaryStream | (FileData | string)[] = null;
3738
@@ -72,12 +73,27 @@
7273
}
7374
}
7475
76+
const is_panel = (v: string): v is Panel => ["top", "blueprint", "selection", "time"].includes(v);
77+
78+
function setup_panels() {
79+
if (rr?.ready && panel_states) {
80+
for (const panel in panel_states) {
81+
// ignore extra properties
82+
if (!is_panel(panel)) continue;
83+
rr.override_panel_state(panel, panel_states[panel]);
84+
}
85+
}
86+
}
87+
7588
onMount(() => {
7689
rr = new WebViewer();
77-
rr.start(undefined, ref, { hide_welcome_screen: true, allow_fullscreen: true }).then(() => {
90+
rr.on("ready", () => {
7891
try_load_value();
92+
setup_panels();
7993
});
94+
rr.on("fullscreen", (on) => rr.toggle_panel_overrides(!on));
8095
96+
rr.start(undefined, ref, { hide_welcome_screen: true, allow_fullscreen: true });
8197
return () => {
8298
rr.stop();
8399
};
@@ -94,6 +110,7 @@
94110
}
95111
96112
$: value, try_load_value();
113+
$: panel_states, setup_panels();
97114
</script>
98115

99116
{#if !interactive}

0 commit comments

Comments
 (0)