Introduction

The knit_targets_mermaid() function provides a powerful way to visualize your targets pipeline as an interactive Mermaid diagram. This vignette demonstrates how to use it in R Markdown or Quarto, including zooming, panning, and rich tooltips with markdown support.

Basic Usage

library(yourpackagename)
# Basic pipeline
knit_targets_mermaid(targets_only = TRUE)

This will render a vertical (top-to-bottom) Mermaid diagram of your pipeline, with zoom and pan enabled.

Customizing the Diagram

You can pass arguments to both targets::tar_mermaid() and targets::tar_manifest() via .... For example, to use a custom pipeline script:

knit_targets_mermaid(script = "my_targets.R", targets_only = TRUE)

Tooltips with Markdown

If you add a description to your targets, it will appear as a tooltip when you hover over the node. Descriptions are parsed as markdown (if the markdown package is installed) and rendered as HTML, so you can use formatting, links, and more:

# In your _targets.R
list(
  tar_target(x, 1 + 1, description = "**Bold** _italic_ [link](https://r-project.org)"),
  tar_target(y, x * 2, description = "`y` is double x.\n- Bullet 1\n- Bullet 2")
)

Example Output

Below is an example of a rendered diagram with tooltips:

Hover over the nodes to see the markdown-formatted tooltips. You can zoom and pan the diagram with your mouse.

Styling and Customization

The function injects custom CSS and JS for zooming, panning, and tooltips. You can further customize the appearance by editing inst/assets/mermaid-zoom.css and inst/assets/mermaid-zoom.js in your package.

Troubleshooting

  • If tooltips do not render as HTML, ensure the markdown package is installed.
  • If you use Quarto, ensure external JS/CSS is allowed in your document settings.

Conclusion

knit_targets_mermaid() makes it easy to create beautiful, interactive, and informative pipeline diagrams for your R projects. Use markdown in your target descriptions for rich tooltips, and enjoy seamless navigation with zoom and pan.