Skip to main content

Running ImJoy in Jupyter notebooks.

Project description

ImJoy RPC

Using ImJoy with Jupyter notebooks

The imjoy-rpc library enables bidirectional RPC calls between the ImJoy core and your python plugin.

The library has an abstract transport interface that can support different types of transport. For now, we support Jupyter comms message which is a custom message protocol used in Jupyter notebooks (for example powers jupyter widgets).

To use it, you need to install the imjoy-rpc library in Python and the notebook extension in javascript.

Install ImJoy RPC and Jupyter notebook extension

pip install -U imjoy-rpc imjoy-jupyter-extension

Use ImJoy plugins inside Jupyter notebooks

Now you can start a jupyter notebook via for example jupyter notebook command, you should be able to see an ImJoy icon in the toolbar if everything goes well.

imjoy in the notebook toolbar

Now run ImJoy plugins in a cell, see an example that uses itk-vtk-viewer to visualize images:

import imageio
import numpy as np
from imjoy_rpc import api

class ImJoyPlugin():
    def setup(self):
        api.log('plugin initialized')

    async def run(self, ctx):
        viewer = await api.showDialog(type="itk-vtk-viewer",
                                      src="https://oeway.github.io/itk-vtk-viewer/")
        # show a 3D volume
        image_array = np.random.randint(0, 255, [10,10,10], dtype='uint8')

        # show a 2D image
        # image_array = imageio.imread('imageio:chelsea.png')

        await viewer.imshow(image_array)

api.export(ImJoyPlugin())

With the above code, you created an ImJoy plugin. To run it, click the Run button with the ImJoy icon. It will then call the run function of your plugin.

Run Jupyter notebook inside ImJoy

You can also do the reverse by running a notebook inside ImJoy, to do that, please first create an empty jupyter notebook. Then copy and paste the url into the "+ PLUGINS" dialog, press enter and install the plugin. Click the newly installed plugin and you will get a notebook page open in ImJoy.

Try to copy and paste the itk-vtk-viewer example to a cell and execute it. Similarily, if you now click the run ImJoy button in the toolbar, you will get the viewer open insided ImJoy.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imjoy-jupyter-extension-0.2.3.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

imjoy_jupyter_extension-0.2.3-py3-none-any.whl (36.5 kB view details)

Uploaded Python 3

File details

Details for the file imjoy-jupyter-extension-0.2.3.tar.gz.

File metadata

  • Download URL: imjoy-jupyter-extension-0.2.3.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.1

File hashes

Hashes for imjoy-jupyter-extension-0.2.3.tar.gz
Algorithm Hash digest
SHA256 3ebb7db314f42bf9e60f618c3908528a704f6401815406b0b479bc8ea942e4b6
MD5 97461fa79c7becddc0bd32c08698fddc
BLAKE2b-256 39ea20adfe0b9f389f2e93e3deef4d984699873ef1c70d9e9c12b54f5dab57a2

See more details on using hashes here.

Provenance

File details

Details for the file imjoy_jupyter_extension-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: imjoy_jupyter_extension-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 36.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.1

File hashes

Hashes for imjoy_jupyter_extension-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 81a7a29857716053d6b9c01e3a4be4d0b421a55b407d1db1bd2ec08b1b48da2f
MD5 d0d0dbf4eda0e902cbda2480dc66c563
BLAKE2b-256 b2f0b01819963a823e24ea19bfe49da6a11b1ecfbb139f1fc6441af6d0ff356e

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page