Repository navigation
Widgets
Widgets are declared inside pages and containers. Use explicit ids for anything interactive or updated.
Contents: Primitive · Data · Inputs · Media
| Category | Widgets |
|---|---|
| Primitive |
text, markdown, metric, alert, progress, header
|
| Data |
chart, sparkline, gauge, table, candlestick (v3), renko (v3), shader (v3) |
| Inputs |
button, toggle, checkbox, select, radio, radio_toggle, text_input, number_input, form
|
| Media |
log, video_hls, mic_button
|
lcars.text("LCARS H1 SAMPLE", size="h1", color="pale-canary", id="headline")
lcars.text("Body text sample.", size="body", id="body")
lcars.text("MONO 1701-D // 47.23", size="mono", color="lilac", id="code")Text sizes: h1, h2, body, mono.
lcars.markdown("### Report\n\n- Rendered markdown\n- Sanitized HTML", id="report")Update markdown with content:
if lcars.button("Refresh Report", id="refresh-report"):
lcars.update("report", content="### Report\n\nComplete")lcars.metric("Warp Core", "98%", status="ok", color="anakiwa", id="warp-core")
lcars.metric("Thermal", "CAUTION", status="warn", id="thermal")
lcars.metric("Fault Bus", "LOCKED", status="crit", id="fault")Statuses: ok, warn, crit.
lcars.alert("Yellow alert simulation channel armed.", level="yellow", id="yellow-alert")
lcars.alert("Red alert banner sample.", level="red", blink=True, id="red-banner")Use set_alert_condition when the whole interface should change alert tint.
lcars.progress("Shield Grid", 74, color="anakiwa", id="shield-grid")Pass values in the 0 to 100 range. Clamp your source value if it can exceed that range.
lcars.header("Operational Summary", size="h3", color="pale-canary", id="ops-header")lcars.chart([18, 21, 26, 34], title="EPS Flow", color="anakiwa", id="eps-flow")
lcars.chart(
{
"EPS A": [18, 21, 26, 34],
"EPS B": [12, 17, 24, 29],
},
title="EPS Comparison",
id="eps-comparison",
)
lcars.sparkline([4, 7, 6, 9, 12], title="Sensor Gain", id="sensor-gain-trace")Accepted chart data:
- Numeric list.
- Dictionary of named numeric lists.
- pandas
DataFrame. - pandas
Series.
Dictionary series should use matching lengths for predictable chart alignment.
lcars.gauge(
"Deflector Load",
72.4,
unit="%",
warn_threshold=75,
crit_threshold=90,
color="orange",
id="deflector-load",
)Choose a value inside min and max; gauges do not clamp automatically.
rows = [
{"System": "Warp Core", "State": "Nominal", "Load": "87%"},
{"System": "Computer", "State": "Synced", "Load": "42%"},
]
lcars.table(rows, title="System Matrix", id="system-matrix")For list[dict], headers come from the first row. Missing keys in later rows render as
empty cells. Extra keys in later rows are ignored unless they appear in the first row.
Zoomable, pannable OHLC candlestick chart powered by TradingView's lightweight-charts.
import lcars_ui as lcars
ohlc = [
{"time": "2024-01-01", "open": 100.0, "high": 110.0, "low": 95.0, "close": 105.0},
{"time": "2024-01-02", "open": 105.0, "high": 115.0, "low": 100.0, "close": 108.0},
]
lcars.candlestick(
ohlc,
title="ES Futures",
up_color="anakiwa",
down_color="hopbush",
id="es-candles",
)Attach trade markers to any bar:
lcars.candlestick(
ohlc,
title="ES Futures",
markers=[
{"time": "2024-01-01", "position": "below", "shape": "arrow_up", "color": "anakiwa", "text": "BUY x4"},
{"time": "2024-01-02", "position": "above", "shape": "arrow_down", "color": "hopbush", "text": "SELL x4"},
],
id="es-candles-marked",
)Marker position: "above", "below", "in". Marker shape: "arrow_up", "arrow_down", "circle", "square".
Data formats accepted: list[dict] with keys time/open/high/low/close (optional volume), or a pandas
DataFrame with matching columns and a DatetimeIndex. If time is missing in a dict row it defaults to
the row index.
Renko bricks are computed server-side from a flat price series; no OHLC data required.
price_series = [100000, 100420, 100180, 100850, 101200, 101050, 101680, 102140]
lcars.renko(
price_series,
brick_size=300.0, # price movement per brick
title="Equity Renko",
up_color="pale-canary",
down_color="hopbush",
id="equity-renko",
)data accepts list[float], list[dict] with a "close" or "price" key, or a pandas Series. Bricks
render without wicks by convention. Markers work exactly like on candlestick.
Runs a GLSL ES 1.00 fragment shader on the GPU, producing animated real-time graphics.
WARP_GLOW = """
void main() {
vec2 uv = (v_uv - 0.5) * vec2(u_resolution.x / u_resolution.y, 1.0);
float r = length(uv);
float pulse = 0.5 + 0.5 * sin(u_time * 2.0 - r * 10.0);
float core = smoothstep(0.9, 0.0, r) * pulse;
gl_FragColor = vec4(u_color * (0.15 + core), 1.0);
}
"""
lcars.shader(
WARP_GLOW,
title="Warp Core",
uniforms={"u_color": [0.973, 0.6, 0.0]}, # orange glow
aspect_ratio=2.0,
id="warp-core",
)Built-in uniforms (always available, no declaration needed):
| Uniform | Type | Value |
|---|---|---|
u_time |
float |
Seconds since widget mounted |
u_resolution |
vec2 |
Canvas size in physical pixels |
v_uv |
vec2 (varying) |
UV coords in [0, 1] |
Custom uniforms via the uniforms dict:
- Single
float→uniform float name; -
list[float]of length 2/3/4 →uniform vec2/vec3/vec4 name;
GLSL shader compile/link errors render as an inline error banner without crashing the page.
execute_clicked = lcars.button("Execute", color="orange", id="execute")
if execute_clicked:
lcars.notify("Execute pressed.")Buttons are momentary. They return True only during the handler rerun caused by that
click.
For very small handlers, inline style is also valid:
if lcars.button("Acknowledge", id="ack"):
lcars.append_log("ops-log", "ACKNOWLEDGE command accepted")autocycle = lcars.toggle("Autocycle", value=True, color="hopbush", id="autocycle")
interlock = lcars.checkbox("Safety Interlock", value=True, color="lilac", id="interlock")
commit_clicked = lcars.button("Commit", id="commit")
if commit_clicked:
lcars.append_log("ops-log", f"autocycle={autocycle} interlock={interlock}")The value= argument is the initial fallback. Browser-session state wins after the user
changes the control.
mode = lcars.select("Mode", ["Cruise", "Alert", "Diagnostics"], value="Cruise", id="mode")
band = lcars.radio("Band", ["A", "B", "C"], value="B", id="band")
gain = lcars.radio_toggle("Gain", ["Low", "Mid", "High"], value="Mid", id="gain")
apply_clicked = lcars.button("Apply Mode", id="apply-mode")
if apply_clicked:
lcars.append_log("ops-log", f"mode={mode} band={band} gain={gain}")If value is omitted, the first option is the default. If options is empty, the return
value is "".
The browser only offers declared options, but custom clients can send arbitrary strings. Validate important choices before acting.
operator = lcars.text_input("Operator Code", placeholder="OPS-01", id="operator-code")
authenticate_clicked = lcars.button("Authenticate", id="authenticate")
if authenticate_clicked:
code = operator.strip()
if not code:
lcars.notify("Operator code required.", level="error")password=True masks browser display but is not encrypted secret storage.
threshold = lcars.number_input(
"Threshold",
value=5.5,
min=0,
max=9.99,
step=0.1,
id="threshold",
)
apply_threshold = lcars.button("Apply Threshold", id="apply-threshold")
if apply_threshold:
lcars.append_log("ops-log", f"threshold={threshold:.1f}")number_input returns a float. Invalid submitted values fall back to the previous
numeric value. New values are clamped to min and max when set.
with lcars.form("Configure Warp", action_id="warp-submit", submit_label="Commit", id="warp-form"):
lcars.number_input("Warp Factor", value=5.0, min=0, max=9.99, id="warp-factor")
lcars.toggle("Inertial Dampeners", value=True, id="dampeners")Forms group child input payloads and hydrate child state. A form can contain only input
widgets. lcars.form() does not currently return a submit flag; use a normal button when
you need a direct Python branch.
warp = lcars.number_input("Warp Factor", value=5.0, min=0, max=9.99, id="warp-factor")
dampeners = lcars.toggle("Inertial Dampeners", value=True, id="dampeners")
commit_warp = lcars.button("Commit Warp", id="commit-warp")
if commit_warp:
lcars.append_log("ops-log", f"warp={warp:.2f} dampeners={dampeners}")lcars.log("ops-log", title="Operations Log", max_lines=50, id="ops-log-widget")
if lcars.button("Acknowledge", id="ack"):
lcars.append_log("ops-log", "ACKNOWLEDGE command accepted")append_log targets the stream id, not the widget id.
lcars.video_hls("/media/demo/manifest.m3u8", title="Local HLS", muted=True, id="video")Use app-local or explicitly allowed HLS manifests.
lcars.mic_button("voice-command", title="Voice Command", id="voice-command-button")Browser microphone access requires HTTPS except on localhost.
See Also: Layouts · Actions and State · Recipes · Reference