Chart-generating function outside Observable

I’m trying to translate a notebook I’ve made into plain javascript to include it in a webpage. I’d like to use a function similar to the calendar one found in this notebook (Calendar / D3 / Observable), that is with destructured arguments, and reusable.

My problem is that I don’t know what happens in Observable after svg.node() has been returned. My attempts with plain d3 in a webpage have all failed. I tried d3.selection.call( myFunction ) and d3.selection.append( myFunction ).

Thanks in advance for your help.

Observable’s Inspector will read the return value (the DOM element) and attach it to the cell’s output wrapper.

In your case you’ll have to append the returned element somewhere in the DOM, e.g.:

document.body.appendChild(Calendar(data))
1 Like

Here’s an example:

1 Like