Published
Edited
Dec 25, 2019
Importers
3 stars
Insert cell
Insert cell
md`This is a range input ${bind(html`<input type=range style="width:80px;">`, viewof apples)}.

This is a number input ${bind(html`<input type=number style="width:80px;">`, viewof apples)}.`
Insert cell
Insert cell
bind(html`<input type=range>`, viewof apples)
Insert cell
Insert cell
viewof apples = new View(3)
Insert cell
Insert cell
new Array(apples + 1).join("🍎")
Insert cell
Insert cell
function bind(input, view) {
const value = ["range", "number"].includes(input.type) ? "valueAsNumber" : "value";
var update;
if (input.type == "file") {
update = () => { };
input.oninput = () => { view.value = input.files };
}
else if (input.type == "radiogroup") {
update = () => { input.setter(view.value) };
input.oninput = () => { view.value = input.getter() };
}
else if (input.type == "checkbox") {
update = () => input.checked = view.value;
input.oninput = () => view.value = input.checked;
}
else {
update = () => input[value] = view.value;
input.oninput = () => view.value = input[value];
}
view.addEventListener("input", update);
disposal(input).then(() => view.removeEventListener("input", update));
return update(), input;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`### Example:`
Insert cell
md `X: ${bindSelect({options:["a","b","c"]}, viewof x)}&nbsp;&nbsp;&nbsp;&nbsp;Y:${bindSliderNumber ({min:0,max:10,step:0.1}, viewof y)}

Z: ${bindCheckbox("z", viewof z)}

W: ${bindRadioGroup ({options:["a","b","c"]}, viewof w)}

S: ${bindCheckGroup ({options:["a","b","c"]}, viewof s)}

F: ${bindFile({multiple:true, accept:".png,.jpg", size:'20em'}, viewof f)}

C: ${bindColor({}, viewof c)}`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof c = new View("#ffaa00")
Insert cell
[x,y,z,w,s]
Insert cell
{
const div = html`<div>`;
div.append(html`<h3>Image:</h3>`);
for (var j = 0; j < f.length; j++) {
let file = f[j];
let img = html`<img height="125px" />`
img.src = await Files.url(f[j]);
div.append(img);
}
return div;
}
Insert cell
md`### Imports`
Insert cell
import {View} from "@mbostock/synchronized-views"
Insert cell
import {disposal} from "@mbostock/disposal"
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