Public
Edited
Jul 18, 2023
3 stars
Insert cell
Insert cell
fetch("https://api.weather.gov/gridpoints/OKX/33,37/forecast").then((response) => response.json())
Insert cell
Insert cell
getWeather = () => fetch("https://api.weather.gov/gridpoints/OKX/33,37/forecast").then((response) => response.json())
Insert cell
Insert cell
<button onClick=${getWeather}>Run</button>
Insert cell
Insert cell
Inputs.button("Run", { reduce: getWeather })
Insert cell
Insert cell
Inputs.button("Run", { reduce: () => console.log(getWeather()) })
Insert cell
Insert cell
Inputs.button("Run", {reduce: (d) => mutable result = getWeather()})
Insert cell
mutable result = null
Insert cell
Insert cell
viewof runner = Inputs.button("Run", { value: null, reduce: getWeather })
Insert cell
runner
Insert cell
Insert cell
Insert cell
viewof weather = Run(getWeather)
Insert cell
Insert cell
weather
Insert cell
Insert cell
Run(async () =>
Plot.lineY((await getWeather()).properties.periods, {
x: (d) => new Date(d.startTime),
y: "temperature"
}).plot()
)
Insert cell
Insert cell
Insert cell
Run = (fn) => {
let button, inspector;
const node = htl.html`<div>
${button = htl.html`<button onClick=${onClick}>Run</button>`}
${inspector = htl.html`<div></div>`}
</div>`;
async function onClick() {
inspector.innerHTML = "";
const value = await Promise.resolve(fn());
inspector.appendChild(value instanceof HTMLElement ? value : inspect(value));
set(node, value);
}
set(node, null);
return node;
}
Insert cell
import {inspect} from "@observablehq/inspector"
Insert cell
import {set} from "@observablehq/synchronized-inputs"
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