Interactive Coding Essentials Cheatsheet

Essential Commands, Tips, and Cell Options for Interactive Coding

Essential commands, tips, and cell options for interactive coding with Quarto Live, WebAssembly, and interactive code blocks.

Tools
Author
Affiliation
Published

March 22, 2025

Keywords

interactive coding, Quarto Live, WebAssembly, interactive R, interactive Python

Interactive Coding Overview

  • Interactive Coding: Execute code blocks interactively in Quarto documents.
  • Engines Supported: webr (R) and pyodide (Python).
  • Key Benefits: Immediate feedback, dynamic visualizations, seamless integration of R and Python.

Learn more in the Introduction to Interactive Coding.



Installing Quarto Live & WebAssembly

Install Quarto Live extension:

quarto add r-wasm/quarto-live

Configure YAML header:

---
format: live-html
---

Detailed instructions in Installing Quarto Live & WebAssembly Engines.

Creating and Managing Interactive Code Blocks

Basic interactive code block example

Source:

```{webr}
print("Hello, Interactive World!")
```
```{pyodide}
print("Hello, Interactive World!")
```

Output:

Explore further in Interactive Code Blocks Explained.

Useful Cell Options:

Option Description Default
autorun Automatically executes code on page load. false
edit Allows editing of code blocks. true
runbutton Shows “Run Code” button. true
completion Enables autocomplete suggestions. true
startover Shows “Start Over” button. true
persist Persists user modifications. false
timelimit Time limit for code execution (seconds). 30
include Display code block output and source. true
min-lines Minimum visible lines in editor. 0
max-lines Maximum visible lines in editor.

Example usage:

```{webr}
#| autorun: true
#| edit: false
summary(cars)
```
```{pyodide}
#| autorun: true
#| edit: false
import numpy as np
np.mean([1, 2, 3, 4, 5])
```

Environment Management and Variable Sharing

Define global setup code:

Execute code globally before other interactive blocks:

```{webr}
#| setup: true
data(iris)
```
```{pyodide}
#| setup: true
import numpy as np
```

Share variables across languages:

Define data from R and consume in Python:

```{webr}
#| define:
#|   - mydata
mydata <- iris
```

```{pyodide}
#| input:
#|   - mydata
import pandas as pd
pd.DataFrame(mydata)
```

Further details in Managing Execution Environments.

Further Reading


Back to top

Reuse

Citation

BibTeX citation:
@online{kassambara2025,
  author = {Kassambara, Alboukadel},
  title = {Interactive {Coding} {Essentials} {Cheatsheet}},
  date = {2025-03-22},
  url = {https://www.datanovia.com/learn/interactive/cheatsheets/interactive-coding-essentials.html},
  langid = {en}
}
For attribution, please cite this work as:
Kassambara, Alboukadel. 2025. “Interactive Coding Essentials Cheatsheet.” March 22, 2025. https://www.datanovia.com/learn/interactive/cheatsheets/interactive-coding-essentials.html.