Public
Edited
Jul 5, 2024
Insert cell
Insert cell
function set(input, value) {
input.value = value;
input.dispatchEvent(new Event("input", { bubbles: true })); // Native events bubble, so we should too
}
Insert cell
Insert cell
Insert cell
DataListInput = (options, { label = "Select an option", value = "" } = {}) => {
const input = htl.html`
<input list="options" placeholder="${label}">
`;
const datalist = htl.html`
<datalist id="options">
${options.map(option => htl.html`<option value="${option}">`)}
</datalist>
`;
const node = htl.html`
<div>
${input}
${datalist}
</div>
`;

// Update the display whenever the value changes
Object.defineProperty(node, "value", {
get() {
return value;
},
set(v) {
value = v;
input.value = v;
}
});

// Handle input changes
input.oninput = (e) => set(node, e.target.value);

// Set the initial value
node.value = value;
return node;
}
Insert cell
Insert cell
viewof gpuOptionsInput = DataListInput(gpuOptions, {label: "Select GPU", value: gpuOptions[0]});

Insert cell
Insert cell
gpuOptionsInput
Insert cell
Insert cell
Inputs.bind(Inputs.radio(gpuOptions, {label: "GPU"}), viewof gpuOptionsInput)
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more