Public
Edited
Apr 25, 2023
1 star
Insert cell
Insert cell
viewof textInput = Inputs.textarea({
label: "Text Input",
placeholder: "Enter some text input...",
value: '{"greeting": "Hello, world!"}'
})
Insert cell
Insert cell
viewof zedQuery1 = Inputs.textarea({
label: "Zed Query",
placeholder: "Enter a Zed query...",
value: "yield greeting"
})
Insert cell
Insert cell
zed = import("https://cdn.jsdelivr.net/npm/@brimdata/zed-wasm@0.0.13/index.js")
Insert cell
Insert cell
result1 = await zed.zq({ input: textInput, program: zedQuery1 })
Insert cell
Insert cell
result1
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
salesData
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
viewof zedQuery2 = Inputs.textarea({
label: "Zed Query",
placeholder: "Enter a Zed query...",
value: "regionRevenue := sum(totalRevenue) by region"
})
Insert cell
result2 = await zed.zq({ input: salesData, program: zedQuery2 })
Insert cell
result2
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
schools = FileAttachment("schools.zng")
Insert cell
Insert cell
viewof zedQuery3 = Inputs.textarea({
label: "Zed Query",
value: "count() by County"
})
Insert cell
Insert cell
result3 = await zed.zq({
input: await schools.stream(),
program: zedQuery3
})
Insert cell
Insert cell
Plot.plot({
width: 1000,
marginBottom: 100,
x: { tickRotate: -90 },
marks: [
Plot.barY(result3, {
x: "County",
y: "count",
sort: { x: "y", reverse: true }
}),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
viewof fileInput = Inputs.file({ label: "Input Data File" })
Insert cell
Insert cell
viewof inputFormat = Inputs.select(
["auto", "arrows", "csv", "json", "line", "zeek", "zjson", "zng", "zson"],
{ label: "Input Format", value: "line" }
)
Insert cell
Insert cell
viewof zedQuery4 = Inputs.textarea({
label: "Zed Query",
placeholder: "Enter a Zed query...",
value: 'yield string(len(this)) + " characters: " + this'
})
Insert cell
Insert cell
result4 = {
if (!fileInput) return [{ message: "Choose a local text file for input" }];
console.log(fileInput);
return await zed.zq({
input: await fileInput.stream(),
program: zedQuery4,
inputFormat: inputFormat
});
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more