What I want to do:
embed a chart, and embed the controls for that chart, from an observable notebook, into a simple reactjs app.
What Happens:
The chart embeds fine, but the control (a slider, imported into the notebook from jeremy’s inputs notebook) renders as below.
This is what it looks like on my observablehq notebook:
@kchalas/calendar-heatmap-too
This is how the control renders on the react app (i tried a simple html file also, with the same results):
What I did try:
I tried with the ‘embed code’ from each of the two cells from my notebook.
I also tried the approach described in the section ‘Rendering Cells’ of jeremy’s guide on embedding notebooks - i have two named cells: ‘cal’ (the calendar chart, which renders fine when i just include one cell), and ‘dataSelector’, which is not working, and apparently i must not have understood the module/runtime behavior, as it reproduces the chart in the second div and renders the slider control as in the screenshot above.
/*
new Runtime().module(notebook, name => {
if (name === "chart") {
return new Inspector(document.querySelector("#chart"));
}
});
*/
//is this wrong to return two inspector objects? i tried other ways as well....
new Runtime().module(notebook, name => {
if (name === "cal") {
console.log("AHA CAL!");
return new Inspector(document.querySelector("#div1"));//i've tried with both custom div IDs, and the ID returned by the 'embed code' cell-menu option.
}
if (name === "dataSelector") {
console.log("AHA SELECT!");
return new Inspector(document.querySelector("#div2"));
}
});
But cant figure out what I am doing wrong. I am sure it’s something simple, i must be missing a key step - but all the examples relating to embedding show a single cell (.e.g: name===‘chart’) but i’ve not been able to find an example with a chart and its controls all embedded into an external app.
I look forward to any advice, thanks in anticipation!
References referred
I believe i have followed recommended steps here:
//how-to-embed-a-notebook-in-a-react-app
here:
//downloading-and-embedding-notebooks
and here:
//breakout