Kino.Output (Kino v0.2.0) View Source

A number of output formats supported by Livebook.

Link to this section Summary

Types

An empty output that should be ignored whenever encountered.

A raw image in the given format.

t()

Livebook cell output may be one of these values and gets rendered accordingly.

Interactive data table.

Standalone text block.

Regular text, adjacent such outputs can be treated as a whole.

Interactive Vega-Lite graphic with data streaming capabilities.

Link to this section Types

Specs

ignored() :: :ignored

An empty output that should be ignored whenever encountered.

Specs

image() :: {:image, content :: binary(), mime_type :: binary()}

A raw image in the given format.

Specs

Livebook cell output may be one of these values and gets rendered accordingly.

Specs

table_dynamic() :: {:table_dynamic, pid()}

Interactive data table.

There should be a server process that serves data requests, filtering, sorting and slicing data as necessary.

Communication protocol

A client process should connect to the server process by sending:

{:connect, pid()}

And expect the following reply:

@type column :: %{
  key: term(),
  label: binary()
}

{:connect_reply, %{
  name: binary(),
  columns: list(column()),
  features: list(:refetch | :pagination | :sorting)
}}

The client may then query for table rows by sending the following requests:

@type rows_spec :: %{
  offset: non_neg_integer(),
  limit: pos_integer(),
  order_by: nil | term(),
  order: :asc | :desc,
}

{:get_rows, pid(), rows_spec()}

To which the server responds with retrieved data:

@type row :: %{
  # An identifier, opaque to the client
  id: term(),
  # A string value for every column key
  fields: list(%{term() => binary()})
}

{:rows, %{
  rows: list(row()),
  total_rows: non_neg_integer(),
  # Possibly an updated columns specification
  columns: :initial | list(column())
}}

Specs

text_block() :: {:text, binary()}

Standalone text block.

Specs

text_inline() :: binary()

Regular text, adjacent such outputs can be treated as a whole.

Specs

vega_lite_dynamic() :: {:vega_lite_dynamic, pid()}

Interactive Vega-Lite graphic with data streaming capabilities.

There should be a server process responsible for communication with subscribers.

Communication protocol

A client process should connect to the server process by sending:

{:connect, pid()}

And expect the following reply:

{:connect_reply, %{spec: map()}}

The server process may then keep sending one of the following events:

{:push, %{data: list(), dataset: binary(), window: non_neg_integer()}}

Specs

vega_lite_static() :: {:vega_lite_static, spec :: map()}

Vega-Lite graphic.

spec should be a valid Vega-Lite specification, essentially JSON represented with Elixir data structures.

Link to this section Functions

Link to this function

image(content, mime_type)

View Source

Specs

image(binary(), binary()) :: t()

See image/0.

Specs

inspect(term()) :: t()

Returns text_block/0 with the inspectd term.

Specs

table_dynamic(pid()) :: t()

See table_dynamic/0.

Specs

text_block(binary()) :: t()

See text_block/0.

Specs

text_inline(binary()) :: t()

See text_inline/0.

Specs

vega_lite_dynamic(pid()) :: t()

See vega_lite_dynamic/0.

Specs

vega_lite_static(vega_lite_spec :: map()) :: t()

See vega_lite_static/0.