Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPython.display.Javascript does not appear to work #202

Open
akaszynski opened this issue Apr 28, 2022 · 1 comment
Open

IPython.display.Javascript does not appear to work #202

akaszynski opened this issue Apr 28, 2022 · 1 comment

Comments

@akaszynski
Copy link

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)
@akhmerov
Copy link
Member

akhmerov commented May 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants