Public
Edited
Dec 11, 2023
Insert cell
Insert cell
viewof map = {
let container = html`<div style='height:400px;' />`;
let app = html`<div>${container}<p>footer</p></div>`;

// Give the container dimensions.
yield app;


let map = new mapboxgl.Map({
container,
center: [4.352731704711914, 50.846272321172954],
zoom: 4,
style: "mapbox://styles/mapbox/light-v9"
});

// Wait until the map loads.
map.on("load", () => {
container.value = map;
container.dispatchEvent(new CustomEvent("input"));
});
}
Insert cell
{
const elem = html`<div></div>`;
ReactDOM.render(htm`<${App} page="All" />`, elem);
return elem;
}
Insert cell
class App extends React.Component {
constructor(props) {
super(props);
this.state = { todos: [] };
}
addTodo() {
const { todos = [] } = this.state;
this.setState({ todos: todos.concat(`Item ${todos.length}`) });
}
render() {
const { todos } = this.state;
const { page } = this.props;
return htm`
<div class="app">
<${Header} name="ToDo's (${page})" />
<ul>
${todos.map(
todo => htm`
<li>${todo}</li>
`
)}
</ul>
<button onClick=${() => this.addTodo()}>Add Todo</button>
<${Footer}>footer content here<//>
</div>
`;
}
}
Insert cell
Insert cell
Insert cell
Insert cell
React = r('react')
Insert cell
ReactDOM = r('react-dom')
Insert cell
htm = import('https://unpkg.com/htm@2?module').then(r => r.default.bind(React.createElement))
Insert cell
mapboxgl = {
const gl = await require("mapbox-gl@0.49");
if (!gl.accessToken) {
gl.accessToken =
"pk.eyJ1IjoidG1jdyIsImEiOiJja3FmbGJoNXMxNmx5Mm9uejIxcmpiNjh2In0.2F8HR-8J859J7frYE6DG9g";
const href = await require.resolve("mapbox-gl@0.49/dist/mapbox-gl.css");
document.head.appendChild(html`<link href=${href} rel=stylesheet>`);
}
return gl;
}
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