Module Jupyter_comm.Manager

User-defined communication

User-defined communication

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');
type target
type comm
module Target : sig ... end
module Comm : sig ... end