You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/documentation/user_guides/notebooks.malloynb
+87Lines changed: 87 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -116,6 +116,93 @@ my-analytics/
116
116
117
117
---
118
118
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 {
| `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:
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
+
119
206
## Tips
120
207
121
208
**Start simple** - Begin with a basic source, run a query, then add complexity.
0 commit comments