March Docs

ScrollTable

lib/scroll/scroll_table.march — Show tabular data as an interactive table.

ScrollTable.csv("data/orders.csv")          -- a CSV file (first row = header)
ScrollTable.json("report.json")             -- a JSON array of objects
ScrollTable.json_at("report.json", ["models"])  -- an array inside an object
ScrollTable.rows(["day", "orders"], [["1", "96"], ["2", "102"]])
ScrollTable.data_frame(df)                   -- a stdlib DataFrame

Each prints one __SCROLL_BLOB__ block of type application/vnd.scroll.table+json, which the notebook renders as a sortable, filterable table with each column's inferred type and its number of missing values. The summary covers every row; at most max_rows() rows are sent to the browser, and the table says how many it is showing.

Payload (one line of JSON): {"columns":[{"name":"orders","type":"int","missing":0}, ...], "rows":[["96", ...], ...], "total": 21, "source": "data/orders.csv"} A missing cell is null; every other cell is its text.

Functions

fncsvcsv(path : String) : Unit#

Show a CSV file. The first row is the header. A file that cannot be read or parsed prints why instead.

fndata_framedata_frame(df : DataFrame.DataFrame) : Unit#

Show a stdlib DataFrame.

fninfer_typeinfer_type(cells : List(String)) : String#

The type of a column from its non-missing cells: int, float, bool, date or text (an all-missing column is text).

fnis_missingis_missing(cell : String) : Bool#

True for a cell that holds no value: empty (after trimming) or one of the usual placeholders NA, N/A, NaN, nan, null, NULL, None.

fnjsonjson(path : String) : Unit do json_at(path, []) end#

Show a JSON file holding an array (see json_value).

fnjson_atjson_at(path : String, keys : List(String)) : Unit#

Show the array found by following keys from the top of a JSON file, e.g. json_at("report.json", ["models"]).

fnjson_celljson_cell(v : JsonValue) : String#

A JSON value as one table cell; arrays and objects are summarized.

fnjson_valuejson_value(v : JsonValue, source : String) : Unit#

Show a JSON array: an array of objects becomes one row per object (columns are every key, in first-seen order); any other array is one value column.

fnlooks_boollooks_bool(s : String) : Bool#

True for true/false in any case.

fnlooks_datelooks_date(s : String) : Bool#

True for a value starting with an ISO date, YYYY-MM-DD.

fnlooks_floatlooks_float(s : String) : Bool#

True for a decimal number: an integer, a decimal point, an exponent.

fnlooks_intlooks_int(s : String) : Bool#

True for an optionally signed run of decimal digits.

fnmake_sentinelmake_sentinel(payload_json : String) : String#

The sentinel block that displays payload (for tests and composition).

fnmax_rowsmax_rows() : Int do 5000 end#

The most rows sent to the browser for one table.

fnmimemime() : String do "application/vnd.scroll.table+json" end#

The MIME type the notebook renders as a table.

fnnumber_textnumber_text(x : Float) : String#

A JSON number as table text: integral values without a decimal point.

fnpayloadpayload(header : List(String), rows : List(List(String)), source : String) : String#

The table payload for header and rows, as one line of JSON. A row shorter than the header is padded with missing cells; extra cells are dropped. source names where the data came from ("" for none).

fnrowsrows(header : List(String), data : List(List(String))) : Unit#

Show rows of text cells under header.