Skip to main content

Observable JS and Mermaid

NBIS Workshop

This document showcases the use of OJS and Mermaid in Quarto.
Author

Roy Francis

Published

02-Nov-2026

1 Observable JS

Quarto natively supports Observable JS for interactive visualizations and analysis in the browser. OJS in Quarto is documented here.

1.1 Read CSV

Specify ojs as the language. Read a CSV file as an array of row objects.

```{ojs}
data = FileAttachment("assets/diamonds.csv").csv({ typed: true})
data
```

1.2 Table

Display the data as a table.

viewof raw_table = Inputs.table(data)

1.3 Scatterplot

Select variables for point color and the x- and y-axes.

viewof col = Inputs.select(["carat","cut","color","clarity","depth","table","price"],{value: "cut", multiple: false, label: "Color"})
viewof x = Inputs.select(["carat","depth","table","price"], {value: "carat", multiple: false, label: "X axis"})
viewof y = Inputs.select(["carat","depth","table","price"], {value: "depth", multiple: false, label: "Y axis"})
Plot.plot({
  color: {legend: true},
  marks: [
    Plot.dot(data, {
      x: x,
      y: y,
      stroke: col,
      title: (d) => `${d.cut}`
    })
  ],
  grid: true
})
Figure 1: Scatterplot A.

2 Mermaid

Quarto natively supports diagrams using Mermaid. Using Mermaid in Quarto is documented here.

2.1 Flowchart

Specify mermaid as the language.

```{mermaid}
flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]
```

flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]

2.2 Gantt charts

```{mermaid}
gantt
    title A Gantt Diagram
    dateFormat YYYY-MM-DD
    section Section
        A task          :a1, 2014-01-01, 30d
        Another task    :after a1, 20d
    section Another
        Task in Another :2014-01-12, 12d
        another task    :24d
```

gantt
    title A Gantt Diagram
    dateFormat YYYY-MM-DD
    section Section
        A task          :a1, 2014-01-01, 30d
        Another task    :after a1, 20d
    section Another
        Task in Another :2014-01-12, 12d
        another task    :24d