jupyter-sphinx icon indicating copy to clipboard operation
jupyter-sphinx copied to clipboard

IPython.display.Javascript does not appear to work

Open akaszynski opened this issue 3 years ago • 1 comments

I'd like to execute JS within the notebook, and rather than including it using the .. raw:: html directive, I'd like to use Jupyter.

The following works within jupyterlab, but not using the jupyter-sphinx extension. I'm guessing that THREE isn't being imported and the library isn't being loaded.

Is there any way to get this to work?


.. jupyter-execute::

    import random
    from IPython.display import clear_output, display, HTML, Javascript

    libs = ["https://cdnjs.cloudflare.com/ajax/libs/three.js/r120/three.js"]
    js_out = Javascript("""
    const scene = new THREE.Scene();
    const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );

    const renderer = new THREE.WebGLRenderer();

    var canvas = renderer.domElement;
    element.append(canvas);

    // renderer.setSize( window.innerWidth, window.innerHeight );
    // document.body.appendChild( renderer.domElement );

    const geometry = new THREE.BoxGeometry();
    const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
    const cube = new THREE.Mesh( geometry, material );
    scene.add( cube );

    camera.position.z = 5;

    function animate() {
        requestAnimationFrame( animate );

        cube.rotation.x += 0.01;
        cube.rotation.y += 0.01;

        renderer.render( scene, camera );
    };

    animate();

    """, lib=libs)
    display(js_out)

akaszynski avatar Apr 28 '22 18:04 akaszynski

This is unexpected: application/javascript mime type is in the default options. Do you apply some custom configuration to jupyter-sphinx?

akhmerov avatar May 01 '22 10:05 akhmerov