Introduction
Interactive documents powered by Quarto Live can download and use additional R and Python packages at runtime. There are two main approaches:
- Installing packages as the document loads: Packages are automatically installed when the document starts.
- Installing packages interactively: Packages are installed from within interactive code blocks.
Installing Packages as the Document Loads
To install packages during the WebAssembly engine startup, add a packages
key under your engine-specific YAML header.
Add your desired R packages under the webr
key. For example:
example-r.qmd
---
format: live-html
webr:
packages:
- dplyr
- palmerpenguins
- ggplot2
---
Specify your Python packages under the pyodide
key. For example:
example-py.qmd
---
format: live-html
pyodide:
packages:
- matplotlib
- numpy
- seaborn
---
Custom Repositories
If your packages aren’t available from the default repositories, you can use custom repositories.
Custom R packages can be compiled for WebAssembly (e.g., using rwasm). Once hosted in a CRAN-like repository (such as R-universe), include the repository URL in your YAML header:
example-r.qmd
---
format: live-html
webr:
packages:
- cli
repos:
- https://r-lib.r-universe.dev
---
For Python packages, if a package is not found in the Pyodide repository, it can be loaded from PyPI using micropip
if the package is a pure Python wheel or a wasm32/emscripten
build. You can also install wheels directly from a URL:
example-py.qmd
---
format: live-html
pyodide:
packages:
- https://username.github.io/mypackage/mypackage-0.0-1-py3-none-any.whl
---
Installing Packages Interactively
You can also install packages interactively within your code blocks.
Use the standard R function install.packages()
to install packages interactively from the webR public package repository. For example:
Pyodide ships with the micropip package, which can be used to install WebAssembly compatible Python packages provided by the Pyodide team using the micropip.install()
function.
In Python, the micropip.install()
function is asynchronous, so ensure you await its execution before using the package.
Conclusion
This guide explains both methods for loading and using packages in interactive Quarto documents. Whether you want packages to be installed automatically at startup or on demand during interactive sessions, these techniques enable you to extend the capabilities of your interactive R and Python code blocks.
For more information, refer to related tutorials on interactive code blocks and hybrid execution.
Further Reading
Interactive Code Blocks Explained
Learn how interactive code blocks are created and customized in Quarto Live.Plotting and Graphics
Explore how to build dynamic visualizations using packages such as ggplot2 in R and matplotlib in Python.Managing Execution Environments
Understand how to control variable sharing and isolate interactive exercises within your documents.Cell Options Reference
For a complete list of all available cell options and advanced configurations in Quarto Live.
Explore More Articles
Here are more articles from the same category to help you dive deeper into the topic.
Reuse
Citation
@online{kassambara2025,
author = {Kassambara, Alboukadel},
title = {Loading and {Using} {Packages}},
date = {2025-03-07},
url = {https://www.datanovia.com/learn/interactive/getting-started/packages.html},
langid = {en}
}