|
| 1 | +--- |
| 2 | +title: Widgets |
| 3 | +description: "Interactive dashboards, charts and plots the agent builds from your vault, kept as files you can embed anywhere." |
| 4 | +sidebar: |
| 5 | + order: 3 |
| 6 | +--- |
| 7 | + |
| 8 | +Ask the agent for a dashboard of your open tasks, a heatmap of when you edit |
| 9 | +notes, or a 3D plot of a function you are studying, and it answers with a |
| 10 | +**widget**: a small interactive page, rendered right there in the chat, built |
| 11 | +from live data in your vault. Keep the ones you like as `.widget` files. They |
| 12 | +open in their own tab, embed in any note, and stay up to date as the vault |
| 13 | +changes. |
| 14 | + |
| 15 | +Widgets need the [`widgets` skill](/agents/skills/), which ships with the plugin |
| 16 | +and is on by default. Live data needs the |
| 17 | +[Dataview](https://github.com/blacksmithgu/obsidian-dataview) plugin; without it |
| 18 | +a widget can still show data the agent gathered, it just won't refresh itself. |
| 19 | + |
| 20 | +## In the chat |
| 21 | + |
| 22 | +A widget renders as a card in the reply, with a small toolbar above it: |
| 23 | + |
| 24 | +- **Expand** opens it almost full-window for a closer look. |
| 25 | +- **Copy as block** puts the widget on the clipboard as a code block you can |
| 26 | + paste into any note, where it renders the same way. |
| 27 | +- **Save as a widget file** writes it to your **Widgets folder** (Settings → |
| 28 | + Agents → Widgets, default `Widgets/`) and opens it. |
| 29 | + |
| 30 | +A widget starts rendering the moment its block is complete, while the rest of |
| 31 | +the reply is still streaming. |
| 32 | + |
| 33 | +## Widget files |
| 34 | + |
| 35 | +A saved widget is a `.widget` file. It behaves like any file in the vault: |
| 36 | + |
| 37 | +- **Its own tab.** Open it from the file explorer or the quick switcher and it |
| 38 | + fills the pane. The tab's context menu adds **Edit source** (a plain-text |
| 39 | + editor for the file, since Obsidian has none for the extension) and |
| 40 | + **Rename…** next to the usual file actions. |
| 41 | +- **Embeddable.** `![[Vault overview.widget]]` renders it inside a note at its |
| 42 | + own height. Hovering a link to it shows the same preview as any page preview. |
| 43 | +- **Live.** Edit the file, or accept an agent's edit to it, and every open tab |
| 44 | + and embed re-renders. |
| 45 | + |
| 46 | +The agent can revise a saved widget the same way it edits notes: it reads the |
| 47 | +file and stages the change, and you review it as the **rendered widget** before |
| 48 | +anything is written. The chat's pending-changes bar previews the proposal in |
| 49 | +place (with the source diff a click away), and the widget's own pane shows the |
| 50 | +proposed version under an accept/reject bar, with a toggle back to the current |
| 51 | +one. |
| 52 | + |
| 53 | +:::note |
| 54 | +Obsidian Sync carries `.widget` files only if **Sync all other types** is on |
| 55 | +in its settings. Links written *inside* a widget open and preview normally but |
| 56 | +don't count as backlinks, since Obsidian's link index reads markdown only. |
| 57 | +::: |
| 58 | + |
| 59 | +## What is in a widget |
| 60 | + |
| 61 | +A widget is an HTML page with a short header: |
| 62 | + |
| 63 | +````markdown |
| 64 | +```s2b-widget |
| 65 | +--- |
| 66 | +title: Notes per tag |
| 67 | +description: The fifteen most-used tags, as a bar chart |
| 68 | +icon: tags |
| 69 | +queries: |
| 70 | + tags: TABLE length(rows) AS n FROM "" FLATTEN file.tags AS tag GROUP BY tag |
| 71 | +--- |
| 72 | +<div id="chart"></div> |
| 73 | +<script> |
| 74 | + s2b.onData(({ tags }) => { /* draw from tags.rows */ }); |
| 75 | +</script> |
| 76 | +``` |
| 77 | +```` |
| 78 | + |
| 79 | +The header keys, all optional: |
| 80 | + |
| 81 | +| Key | What it does | |
| 82 | +| --- | --- | |
| 83 | +| `title` | Shown on the card and the tab; the file name when saved | |
| 84 | +| `description` | One line on what the widget shows. With the title, the only part of a saved widget that search indexes | |
| 85 | +| `icon` | Any [Lucide](https://lucide.dev/icons/) icon name for the tab and card; the default is `component` | |
| 86 | +| `height` | A fixed height in pixels. Without it the widget sizes to its content; with it, it still shrinks when the content is shorter | |
| 87 | +| `queries` | Named [Dataview](https://blacksmithgu.github.io/obsidian-dataview/queries/structure/) queries. The plugin runs them, hands the results to the widget, and runs them again whenever the vault changes | |
| 88 | +| `libs` | Bundled libraries to load. Currently `plotly`, for 2D and 3D plots | |
| 89 | + |
| 90 | +The `.widget` file is exactly this, without the fence lines. You never need to |
| 91 | +write one by hand, but you can, and the source editor shows the header keys as |
| 92 | +a reminder. |
| 93 | + |
| 94 | +### Links to notes |
| 95 | + |
| 96 | +Anything in a widget marked with `data-note="Path/To/Note.md"` (or a plain link |
| 97 | +whose target is a vault path) is a note link: click opens the note, Cmd/Ctrl-click |
| 98 | +opens it in a new tab, and hovering shows a page preview. Page preview lists |
| 99 | +widgets as their own source, **S2B Widgets**, so you can decide there whether the |
| 100 | +preview needs a modifier key, as for any other source. |
| 101 | + |
| 102 | +### Plots |
| 103 | + |
| 104 | +With `libs: plotly` a widget gets [Plotly](https://plotly.com/javascript/) for |
| 105 | +line, scatter, bar and pie charts, and for 3D surfaces, scatter and meshes with |
| 106 | +orbit and zoom. The build is bundled with the plugin, so plots work offline like |
| 107 | +everything else. Without a library, a widget can still draw with SVG or a |
| 108 | +canvas. |
| 109 | + |
| 110 | +## Widgets are sandboxed |
| 111 | + |
| 112 | +A widget is code the agent wrote, so it runs in a box: |
| 113 | + |
| 114 | +- It renders in an isolated frame with **no access to Obsidian, your vault, or |
| 115 | + the network**. It cannot fetch, load remote scripts, or navigate anywhere. |
| 116 | +- The **plugin** runs the widget's queries and passes the results in. The |
| 117 | + widget sees only what its own queries return. |
| 118 | +- Libraries are bundled with the plugin, never downloaded. |
| 119 | + |
| 120 | +Treat a widget like anything else the agent produces: it can only act on data |
| 121 | +you let the agent read. |
| 122 | + |
| 123 | +## Widgets and search |
| 124 | + |
| 125 | +A saved widget is indexed by its **title and description only**, so you and |
| 126 | +the agent can find "the tags overview" without its code ever showing up as a |
| 127 | +search result. A widget pasted into a note as a block is likewise reduced to a |
| 128 | +marker with its title before that note is indexed. |
0 commit comments