Skip to content

Commit fc27072

Browse files
authored
docs: add Interactive Filters section to notebooks guide (#267)
Signed-off-by: James Swirhun <james@ms2.co>
1 parent 21e396d commit fc27072

2 files changed

Lines changed: 91 additions & 1 deletion

File tree

scripts/render_document.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,10 @@ class Renderer {
364364
return text;
365365
}
366366
this.links.push({ link: href, style: "md", position });
367-
href = href.replace(/\.malloynb$/, "").replace(/\.malloynb#/, "#");
367+
// Only strip .malloynb from internal links, not external URLs
368+
if (!href.startsWith("http://") && !href.startsWith("https://")) {
369+
href = href.replace(/\.malloynb$/, "").replace(/\.malloynb#/, "#");
370+
}
368371
let out = href.startsWith("/")
369372
? `<a href="${DEFAULT_CONTEXT.site.baseurl}${href}"`
370373
: `<a href="${href}"`;

src/documentation/user_guides/notebooks.malloynb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,93 @@ my-analytics/
116116

117117
---
118118

119+
## Interactive Filters
120+
121+
Notebooks can include interactive dropdown filters that allow viewers to filter query results dynamically. When a user selects filter values, all queries in the notebook automatically re-execute with those filters applied.
122+
123+
> **Note:** Interactive filters are rendered when viewing notebooks via [Publisher](publishing/publishing.malloynb) or the Publisher SDK. They are not currently displayed in VS Code—that capability is coming soon.
124+
125+
### How It Works
126+
127+
1. **Annotate dimensions** in your Malloy source files to mark them as filterable
128+
2. **Add a `##(filters)` annotation** in your notebook to specify which dimensions appear as filter controls
129+
3. When published, the notebook displays filter dropdowns that users can interact with
130+
131+
### Step 1: Annotate Filterable Dimensions
132+
133+
In your Malloy source file, add `#(filter)` annotations to dimensions you want to expose as filters:
134+
135+
```malloy
136+
source: flights is duckdb.table('data/flights.parquet') extend {
137+
dimension:
138+
// Multi-select dropdown for string values
139+
#(filter) {"type": "Star"}
140+
origin_code is origin
141+
142+
// Date range picker
143+
#(filter) {"type": "DateMinMax"}
144+
flight_departure is dep_time
145+
146+
join_one: carriers with carrier
147+
}
148+
149+
source: carriers is duckdb.table('data/carriers.parquet') extend {
150+
dimension:
151+
#(filter) {"type": "Star"}
152+
nickname is nickname_old
153+
}
154+
```
155+
156+
### Filter Types
157+
158+
| Type | UI Component | Use Case |
159+
|------|--------------|----------|
160+
| `Star` | Multi-select dropdown | String fields with discrete values |
161+
| `MinMax` | Numeric input | Numeric fields |
162+
| `DateMinMax` | Date range picker | Date/timestamp fields |
163+
| `Boolean` | Toggle selector | Boolean fields |
164+
165+
### Step 2: Add Notebook Filter Annotation
166+
167+
In your notebook, add a `##(filters)` annotation in the code cell that imports your model. The annotation lists which dimensions should appear as filters using `source.dimension` format:
168+
169+
```malloy
170+
##(filters) ["flights.origin_code", "carriers.nickname", "flights.flight_departure"]
171+
import {flights, carriers} from 'flights.malloy'
172+
```
173+
174+
The filter type for each dimension is determined by the `#(filter)` annotation on that dimension in the source file.
175+
176+
### Custom Labels
177+
178+
By default, filters display the dimension field name. You can customize the label using the `# label="..."` annotation in your source file:
179+
180+
```malloy
181+
source: recalls is duckdb.table('data/recalls.csv') extend {
182+
dimension:
183+
#(filter) {"type": "Star"}
184+
# label="Vehicle Manufacturer"
185+
Manufacturer is Manufacturer_old
186+
}
187+
```
188+
189+
### Match Types
190+
191+
Each filter type supports different match types that users can select:
192+
193+
| Filter Type | Available Match Types |
194+
|------------|----------------------|
195+
| Star | Equals, Contains |
196+
| MinMax | Equals, Less Than, Greater Than, Between |
197+
| DateMinMax | Equals, Before, After, Between |
198+
| Boolean | Equals (True/False) |
199+
200+
### Example
201+
202+
See the [Carrier Analysis notebook](https://github.com/credibledata/malloy-samples/blob/main/faa/carrier_analysis.malloynb#L4) and [Auto Recalls notebook](https://github.com/credibledata/malloy-samples/blob/main/auto_recalls/README.malloynb#L10) for working examples of interactive filters.
203+
204+
---
205+
119206
## Tips
120207

121208
**Start simple** - Begin with a basic source, run a query, then add complexity.

0 commit comments

Comments
 (0)