Name: jvm-repr
Owner: Two Sigma
Description: API for converting JVM objects to representations by MIME type, for the Jupyter ecosystem.
Forked from: jupyter/jvm-repr
Created: 2017-11-13 15:49:10.0
Updated: 2017-11-13 15:49:12.0
Pushed: 2017-11-13 15:56:57.0
Homepage: null
Size: 15
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Configuration | Usage for Library Authors | Usage for Kernel Authors
Standardizing object representation and inspection across JVM kernels (Scala, Clojure, Groovy, …).
JVM languages use various conventions to convert REPL outputs to forms that can be displayed. This project is an attempt to standardize by providing an API that libraries can use to register display methods for any jupyter frontend, whether console, notebook, or dashboard.
This API has two main uses:
As it is with IPython, this is a contract between the libraries within the ecosystem, the kernel that inspects the objects, and the frontends that display them.
See instructions on JitPack for gradle, maven, sbt, or leiningen.
Library authors can register conversion code by implementing a Displayer
and registering it with Displayers
.
For example, the following will register a displayer for Vegas graphs:
rt java.util.Map
rt jupyter.Displayer
rt jupyter.Displayers
rt scala.collection.JavaConverters._
rt vegas.DSL.ExtendedUnitSpecBuilder
splayers.register(classOf[ExtendedUnitSpecBuilder],
new Displayer[ExtendedUnitSpecBuilder] {
override def display(plot: ExtendedUnitSpecBuilder): Map[String, String] = {
val plotAsJson = plot.toJson
Map(
"text/plain" -> plotAsJson,
"application/json" -> plotAsJson,
"text/html" -> new StaticHTMLRenderer(plotAsJson).frameHTML()
).asJava
}
})
Any kernel implementation can use the method to display Vegas graphs for the DSL objects.
Library authors can optionally implement setMimeTypes(String...)
to receive
hints for the MIME types that the kernel or front-end supports. It is
recommended that library authors use these hints to avoid expensive conversions.
Kernel authors can use this API to display registered objects:
rt java.util.Map
..
ject result = interpreter.eval(code);
p<String, String> resultByMIME = Displayers.display(result);
rnel.this.display(resultByMIME);
Kernel authors can optionally call Displayers.setMimeTypes(String...)
to send
hints to display implementations with the set of MIME types that can be used by
the kernel or front-end.