package jupyter

  1. Overview
  2. Docs

Module Jupyter_comm.ManagerSource

User-defined communication

  • since 0.1.0

User-defined communication

  • since 0.1.0

This module provides communication of arbitrary JSON data between the OCaml REPL and the Jupyter. See Comms (Jupyter Notebook Docs) for details.

Opening a comm from the REPL

OCaml:

  let target = Target.create "comm-test" in
  let comm = Comm.create target in   (* Send comm_open to the frontend *)
  Comm.send comm (`String "Hello") ; (* Send comm_msg to the frontend *)
  Comm.close comm                    (* Send comm_close to the frontend *)

JavaScript:

  Jupyter.notebook.kernel.comm_manager.register_target('comm-test', function(comm, msg){
      console.log('opened comm', msg);
      comm.recv_msg(function (msg) { console.log('got msg', msg); });
    })

Opening a comm from the frontend

OCaml:

  let target = Target.create "comm-test"
      ~recv_open:(fun comm json -> ...) (* Receive json = `String "opening" *)
      ~recv_msg:(fun comm json -> ...) (* Receive json = `String "msg" *)
      ~recv_close:(fun comm json -> ...) (* Receive json = `String "closing" *)

JavaScript:

  comm = Jupyter.notebook.kernel.comm_manager.new_comm('comm-test', 'opening');
  comm.send('msg');
  comm.close('closing');
Sourcetype target
Sourcetype comm
Sourcemodule Target : sig ... end
Sourcemodule Comm : sig ... end
OCaml

Innovation. Community. Security.