Search code examples
javascriptd3.jsobservablehq

Remove Cells from D3 Observable When Embedding into Application


Say I am embedding this visual from D3 Observable into my own application. We can embed these by downloading the tarball file:

enter image description here

But this downloads all the cells that are useful for running the notebook online but are no longer needed when showing the visual in an application. How can I remove these cells?

enter image description here

I can run:

$('span').remove() 

...but there must be a better way.


Solution

  • Sure thing – to just display the chart cell, you can change

    const main = runtime.module(define, Inspector.into(document.body));
    

    Which displays all the cells, with

    const main = runtime.module(define, name => {
      if (name == 'chart') {
        return new Inspector(document.body)
      }
    });
    

    Which looks just for the cell named 'chart'.