Executable data loader examples

Observable Framework supports arbitrary executable (.exe) data loaders, which can be any arbitrary executable (e.g. compiled from C) but often specify another interpreter using a shebang as shown in the examples below. Unlike interpreted data loaders (e.g. Python, R), executable data loaders require that you make the loader executable, typically done via chmod. For example:

chmod +x docs/quakes.csv.exe

JPEG

The data loader below specifies the R interpreter, Rscript, to execute the file (#!/usr/bin/env Rscript). A scatterplot chart built with ggplot2 using the built-in diamonds dataset is returned as a JPEG to standard output.

Create a file in your project source root with the .jpeg.exe double extension (for example, docs/data/my-chart.jpeg.exe). Remember to make the script executable, for example using:

chmod +x docs/data/my-chart.jpeg.exe

Then, paste the code below to get started.

Access the output of the data loader from the client using FileAttachment:

const diamonds = FileAttachment("data/diamonds.jpeg").image({width: 500});

The file attachment name does not include the .exe extension. We rely on Framework’s routing to run the appropriate data loader.

We can now view the image:

diamonds

TXT

The data loader below specifies the Julia language interpreter using the shebang (#!/usr/bin/env julia). Text of Edgar Allen Poe's The Raven is accessed from Project Gutenberg. The text is parsed and single paragraph (specified by number) is returned as text.

Create a file in your project source root with the .txt.exe double extension (for example, docs/data/my-chart.txt.exe). Remember to make the script executable, for example using:

chmod +x docs/data/my-chart.txt.exe

Then, paste the code below to get started.

Access the output of the data loader from the client using FileAttachment:

const ravenParagraph = FileAttachment("data/raven.txt").text();

The file attachment name does not include the .exe extension. We rely on Framework’s routing to run the appropriate data loader.

We can now view the paragraph text:

ravenParagraph