WebR Playground
This page demonstrates the interactive R capabilities provided by the vitepress-webr package. WebR allows you to run R code directly in the browser without any server-side setup.
Usage Guide
- Click "Run" to execute R code
- All code blocks share the same R environment on this page
- WebR downloads on first use (~20MB)
Basic Examples
Start with simple R expressions:
Hello World
Idle
Vector operations
Idle
Working with data frames
Idle
Data Visualization
Create beautiful plots with R's graphics system:
Basic scatter plot
Idle
Box plot
Idle
Histogram with normal curve
Idle
Line plot with multiple series
Idle
Statistical Analysis
Perform statistical tests and modeling:
Linear regression
Idle
Correlation analysis
Idle
T-test
Idle
Advanced: ggplot2 (if available)
Note: ggplot2 may need to be loaded. Try this example:
ggplot2 example
Idle
Variable Persistence
Variables are shared across code blocks on this page:
Define variables
Idle
Reuse variables from previous block
Idle
Markdown Syntax
You can use the webr language identifier in code blocks to create interactive cells:
markdown
```webr
print("Hello")
```
```webr title="With Title"
print("Hello")
```Important Notes
- First run: Downloads WebR runtime (~20MB); subsequent runs are instant
- Variable persistence: Variables persist within this page; navigating away resets the environment
- Package availability: Core R packages are available; some additional packages may need to be loaded
- Performance: Most R operations run with good performance via WebAssembly
Limitations
- Not all R packages are available in WebR
- Some packages requiring system dependencies may not work
- Large datasets may consume significant browser memory