Skip to content

Widgets of your own

The built-in widgets cover the standard kinds of devices. When you need one that shows a value the way your lab wants it, or that combines several devices, write your own. A widget is a React component in a file of your workspace. You do not need Node or a build setup: LabOrchestra builds it when you save the file.

  1. On the dashboard, click Edit, then Add widget, and at the end of the panel New widget….

    The dialog New widget with two templates, Blank widget and Device with a control, and a field for the name.The dialog New widget with two templates, Blank widget and Device with a control, and a field for the name.
  2. Choose a template, name the widget in snake_case (big_pressure), and click Create. The file widgets/big_pressure.tsx is in your workspace; a type file, laborchestra-widget.d.ts, is put next to it so that your editor knows the SDK (the server keeps it there up to date, also for a workspace whose widgets you write by hand).

  3. Open the file in your editor and change it. Every time you save, the dashboard loads the new version without a reload.

  4. Your widget appears in the Add widget panel, next to every device it fits. Click it, or drag it to its place.

widgets/big_pressure.tsx
import { Tile, useDevice } from '@laborchestra/widget';
export const meta = { title: 'Big pressure', size: 'S', profile: 'pressure_sensor' };
export default function BigPressure({ device }: { device: string }) {
const d = useDevice(device);
const pressure = d?.state.channels?.[0]?.pressure;
return (
<Tile label={device} testId="big-pressure">
<span className="text-3xl font-bold text-accent">{pressure == null ? '–' : pressure.toExponential(1)}</span>
</Tile>
);
}
  • default is the component. It receives { id, device, info, props }: the device it is shown for, its current status and state, and the settings of this instance.
  • meta tells the Add widget panel what the widget is. title; size: 'main' (fills a pane, like an oscilloscope), 'S' (a small tile) or 'M' (a wider one); profile: offer it only for devices of that profile, or leave it out for any device; needsDevice: false for widgets that belong to no device; description: one line for the panel (keep the title short: a long one is cut off); props: settings that the ⚙ dialog of the widget edits (name, label, type, default, limits).
  • useDevice(id) gives the status and state of a device, and device.action("set_power", 0, -10) calls one of its actions. useStream gives a live stream, useRecording the recording status. The widget SDK reference lists everything.
  • Tailwind classes work. The server builds one stylesheet from the dashboard and all widgets, with the same colours as the rest (bg-panel, text-muted, text-accent, …). Class names that you assemble from pieces (`bg-${color}-500`) are not found; write them out.
  • Other npm packages (a plotting library, say) are bundled into your widget: run npm install in the widgets/ folder. react and @laborchestra/widget come from the page, so there is only one React.

A widget can also be a folder, widgets/big_pressure/index.tsx, with more files in it.

A mistake in the file is shown in place of the widget, where you will see it: a build error with the line, or the error that the widget threw while it ran. Other widgets are not affected. The build error is just esbuild’s message (file, line, column, the line itself). The same errors go to the server’s log, with the source client; an AI assistant sees build errors with the MCP tools get_problems and list_widgets.

The server builds widgets with esbuild, which comes with the release. If it cannot be found (a source checkout without it), the widgets say “esbuild was not found” instead of failing quietly. The setting esbuild names another program; see server settings.

Widgets can also come with a device package.