Skip navigation

The previous post had some hacky R code to grab seekrit JSON data in ObservableHQ (OHQ) Notebooks and spit out a directory with a Quarto qmd and any associated FileAttachments. Holding firm to my “no more generic public R packages” decree, that’s as far as the R code for that utility is going to get.

Quarto, by design, is not married to the R ecosystem. This should help it get more traction in and outside of the broader data science crowd than R Markdown was able to attain. One big element that makes Quarto enticing to me is that it ships with the Observable runtime and stdlib. Observable javascript tools make coding up reactive data visualizations and analyses fun, but I still really dislike using a browser for data science work. I’d much rather use Quarto’s {ojs} sections in a proper editor/IDE when iterating over a concept.

I also learn best by example-first -> experiment-second. Up until now, I’ve been doing the example-ing and experiment-ing over at OHQ. When I discovered that the OHQ notebook code and metadata ships with the HTML page of the notebook (in a JSON <script> block at the end of the document) I just had to build a tool to yank that out and turn it into a Quarto project.

The R code in the previous post is fine for R folks (someone should 100% take that, make it nicer, and turn it into a small package with an RStudio addin and CLI wrapper; no credit back to me is required), but — as noted above — Quarto is not just for R folks. Rather than confine a conversion utility to some scripting language, I decided to port the R experiment over to Rust. That is how ohq2quarto was born.

You can grab Windows & macOS binaries from the Releases, or just:

cargo install --git

to install it if you’re on Linux or already have a Rust environment setup. I’m working on the configuration of a GitHub Action that will make shipping binaries for all platforms stupid simple and automated.

When run in verbose mode, you’ll see something like this when converting a notebook:

$ ohq2quarto --ohq-ref @hrbrmstr/just-one-more-thing --output-dir ./examples --verbose 
      Title: Just One More Thing
       Slug: just-one-more-thing
  Author(s): boB Rudis
  Copyright: Copyright 2022 boB Rudis
    License: "mit"

A look at examples shows:

$ tree examples
├── _quarto.yml
├── columbo_data.csv
└── just-one-more-thing.qmd

The utility made the directory, created the qmd and downloaded the FileAttachment.

This is what the first few lines of the qmd look like:

$ head -16 examples/just-one-more-thing.qmd
title: 'Just One More Thing'
author: 'boB Rudis'
format: html
echo: false
observable: ''

md`# Just One More Thing`

md`This week, Chris Holmes tweeted something super dangerous:`


I’ve tried it on some seriously complex OHQ notebooks and it seems to do what I’ve claimed it does on the tin’s label. If you run into issues, or have some feature requests, please drop an issue in the repo.

One Trackback/Pingback

  1. […] previous post announced a Rust-based command line tool for generating Quarto projects from Observable […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.