/custom-visuals:r-visualsfrom custom-visuals
Creates and manages R visuals in Power BI PBIR reports using ggplot2. Handles scriptVisual configuration, ggplot2 patterns, and script injection into visual.json.
Ships in custom-visuals. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Report modification requires tooling. Two paths exist:
pbirCLI (preferred) -- use thepbircommand and thepbir-cliskill. Install withuv tool install pbir-cliorpip install pbir-clion macOS or Windows; on Linux run thepbir-cliskill'sbin/install-linux.sh, which installs the Windows build under Wine (path 2 only where there is no Wine). Check availability withpbir --version.- Direct JSON modification -- if
pbiris not available, use thepbir-formatskill (pbip plugin) for PBIR JSON structure and patterns. Validate every change withjq empty <file.json>.If neither the
pbir-cliskill nor thepbir-formatskill is loaded, ask the user to install the appropriate plugin before proceeding with report modifications.
R visuals execute R scripts (primarily ggplot2) to render static PNG images on the Power BI canvas. ggplot2 is the preferred library -- its grammar of graphics approach produces clean, publication-quality statistical visualizations with less code. R is particularly strong for statistical visualizations.
scriptVisualValues (columns and measures, multiple allowed)dataset (data.frame, auto-injected)Create the visual.json file manually (see pbir-format skill in the pbip plugin for JSON structure) with visualType: scriptVisual, field bindings for the columns and measures you need (use Values:Table.Column or Values:Table.Measure format), and position/size as required.
library(ggplot2)
p <- ggplot(dataset, aes(x=Date, y=Sales)) +
geom_col(fill="#5B8DBE") +
theme_minimal(base_size=12) +
theme(panel.grid.major.x=element_blank())
print(p) # MANDATORY for ggplot2
Critical rules:
print(p) is mandatory for ggplot2 objects -- they do not auto-display in Power BIdataset is auto-injected as a data.frame; do not create itdataset[,1]) to avoid name escaping issuesdataset$`Order Lines`Before presenting the script to the user, dispatch the r-reviewer agent to validate correctness and provide design feedback.
Set the script content in the visual's objects.script[0].properties.source literal value (see PBIR Format section below).
Escaping rules for visual.json injection:
The script must be encoded as a single-quoted DAX literal string inside expr.Literal.Value:
\n in the JSON string"#5B8DBE") become \" in the JSON string'library(ggplot2)\n...\nprint(p)'examples/visual/ for a complete real-world visual.json showing this encodingValidate JSON syntax with jq empty <visual.json> and inspect the visual.json to confirm script content and field bindings.
Scripts are stored in visual.objects.script[0].properties:
{
"source": {"expr": {"Literal": {"Value": "'library(ggplot2)\\n...\\nprint(p)'"}}},
"provider": {"expr": {"Literal": {"Value": "'R'"}}}
}
Identical structure to Python visuals except visualType is scriptVisual and provider is 'R'.
| Package | Version | Purpose |
|---|---|---|
| ggplot2 | 3.5.1 | Grammar of graphics |
| dplyr | 1.1.4 | Data manipulation |
| tidyr | 1.3.1 | Data tidying |
| ggrepel | 0.9.5 | Non-overlapping labels |
| patchwork | 1.2.0 | Compose multiple plots |
| cowplot | 1.1.3 | Publication-quality plots |
| corrplot | 0.94 | Correlation matrices |
| viridis | 0.6.5 | Color scales |
| RColorBrewer | 1.1-3 | Color palettes |
| forecast | 8.23.0 | Time series forecasting |
| pheatmap | 1.0.12 | Heatmaps |
| treemap | 2.4-4 | Treemaps |
| lattice | 0.22-6 | Trellis graphics |
~1000 CRAN packages available. Not supported: packages requiring networking (RgoogleMaps, mailR).
Full package list: https://learn.microsoft.com/power-bi/connect-data/service-r-packages-support
Any locally installed R package works without restriction. R must be installed separately.
print(p) -- ggplot2 objects require explicit printingif (nrow(dataset) == 0) { plot.new(); text(0.5, 0.5, "No data") }dataset[,1] avoids name escaping issuestheme_minimal() -- clean aesthetic that works well with Power BIfactor()plot.margin=margin(t, r, b, l) to prevent clipping| Constraint | Desktop | Service |
|---|---|---|
| Output | Static PNG, 72 DPI | Static PNG, 72 DPI |
| Timeout | 5 minutes | 1 minute |
| Row limit | 150,000 | 150,000 |
| Output size | 2 MB | 30 MB |
| Networking | Unrestricted | Blocked |
| Gateway | Personal only | Personal only |
| Cross-filter FROM | Not supported | Not supported |
| Receive cross-filter | Yes | Yes |
| Publish to web | Not supported | Not supported |
| Embed (app-owns-data) | Not supported | Not supported |
library(ggplot2)
# 1. Guard against empty data
if (nrow(dataset) == 0) {
plot.new()
text(0.5, 0.5, "No data available", cex=1.5)
} else {
# 2. Data preparation (index-based access)
df <- data.frame(
category = dataset[,1],
value = dataset[,2]
)
# 3. Create visualization
p <- ggplot(df, aes(x=reorder(category, -value), y=value)) +
geom_col(fill="#5B8DBE", width=0.7) +
theme_minimal(base_size=12) +
theme(
panel.grid.major.x = element_blank(),
axis.title = element_blank()
)
# 4. Render
print(p)
}
For the language-choice decision, see the "When to Use a Script Visual" section above. This table covers only mechanical syntax differences for scripts already committed to R:
| Aspect | R (scriptVisual) | Python (pythonVisual) |
|---|---|---|
| Render call | print(p) | plt.show() |
| Column access | dataset[,1] or dataset$col | dataset.iloc[:,0] or dataset["col"] |
| Empty guard | if (nrow(dataset) == 0) | if len(dataset) == 0: |
| Factor/category order | factor(x, levels=...) | pd.Categorical(x, categories=...) |
| Runtime (Service) | R 4.3.3 | Python 3.11 |
Reach for an R visual only when all of the following hold:
If interactivity or cross-filtering matters, use Deneb (a static PNG cannot be a selection source). If the need is a small inline mark (sparkline, bar, status pill), use an SVG measure (no row cap, no timeout, no licensing/region gate, renders under publish-to-web). The script visual's niche is narrow: compute-at-render statistical plots for internal or org consumption.
R vs Python once a script visual is the right call: use R for publication-quality statistical defaults and packages with no Python peer (forecast, corrplot, pheatmap, ridgeline/violin). Use Python when the computation leans on scikit-learn, statsmodels, or scipy, or when surrounding report logic is already Python. Where equal, default to whichever language the report's other scripts use; mixing doubles the publish-time package surface to validate.
Do not default to a script visual because a chart type "looks statistical." A box plot, lollipop, or dumbbell is an SVG-measure or Deneb job; reserve scripts for charts that genuinely compute.
references/data-model.md -- dataset grouping mechanic, row/byte caps, forcing per-row input, and R-specific traps (Time type, text rendering flags, CJK fonts)references/community-examples.md -- R Graph Gallery examples organized by chart type (distribution, correlation, ranking, evolution, flow)references/ggplot2-patterns.md -- Common ggplot2 chart patterns (bar, donut, line, heatmap, bullet)examples/script/ -- Standalone R scripts (bar-chart, trend-line) -- ready to inject into visual.json after escapingexamples/visual/bullet-chart.json -- PBIR visual.json: bullet chart with conditional coloring, error handling, and extensive escapingexamples/visual/bar-chart.json -- PBIR visual.json: horizontal bar with PY comparison lines and colored account labelsexamples/visual/trend-line.json -- PBIR visual.json: area chart with ribbon plot and month factor handlingTo retrieve current R visual / package support docs, use microsoft_docs_search + microsoft_docs_fetch (MCP) if available, otherwise search https://learn.microsoft.com and fetch the relevant pages. Search based on the user's request and run multiple searches as needed to ensure sufficient context before proceeding.
pbi-report-design -- Layout and design best practicespython-visuals -- Python Script visuals (same concept, different language)deneb-visuals -- Vega/Vega-Lite visuals (interactive, vector-based alternative)svg-visuals -- SVG via DAX measures (lightweight inline graphics)pbir-format (pbip plugin) -- PBIR JSON format referenceexamples/script/bar-chart.R (opens in a new tab)examples/script/trend-line.R (opens in a new tab)examples/visual/bar-chart.json (opens in a new tab)examples/visual/bullet-chart.json (opens in a new tab)examples/visual/trend-line.json (opens in a new tab)examples/visual/ytd-line-chart.json (opens in a new tab)references/community-examples.md (opens in a new tab)references/data-model.md (opens in a new tab)references/ggplot2-patterns.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub insightfulanalytics/pbi_agentic_dev --plugin custom-visuals7 skills in this plugin
/deneb-pbirRound-trip TOOLING for Deneb specs in PBIR. Extract/embed the Vega/Vega-Lite spec in visual.json, offline-render it to PNG/SVG, audit a visual's Deneb 2.0 stamps and migrate container signal names. Use whenever a task edits a Deneb visual's spec ("edit the Deneb visual", patching jsonSpec) or needs it rendered without Power BI. Authoring rules live in custom-visuals:deneb-visuals./deneb-visualsDeneb visual creation, Vega/Vega-Lite spec authoring, and Deneb best practices for PBIR reports. Automatically invoke whenever the user mentions "Deneb" in any context, or asks about Vega/Vega-Lite specs in Power BI, Deneb cross-filtering, Deneb interactivity, pbiColor theme integration, Deneb field name escaping, or Deneb rendering issues./performant-matrixDiagnose a slow financial matrix before fixing it: separate row-dispatch cost from the per-cell format-string and conditional-formatting tax, then choose with the user between a bridge table, a native restructure or a Deneb grid. Use when a P&L or financial matrix is slow or will not render (SWITCH dispatch, a calculation group on rows, Performance Analyzer far above the DAX time)./powerbi-custom-visualsPower BI custom visual (.pbiviz) development with the pbiviz toolchain and its MCP server. Automatically invoke when the user mentions "custom visual", "pbiviz", "develop a Power BI visual", "powerbi-visuals-tools", "IVisual", "capabilities.json", "visual formatting model", "visual certification", "publish a visual to AppSource", or asks to scaffold, build, debug, package, certify, or publish a .pbiviz developer visual./python-visualsPython visual creation and matplotlib/seaborn patterns for PBIR reports. Automatically invoke when the user mentions "Python visual", "matplotlib in Power BI", "seaborn in Power BI", "pythonVisual", or asks to "create a Python visual", "add a matplotlib chart", "write a Python visual script"./svg-visualsSVG generation via DAX measures and extension measures with ImageUrl data category for inline visualizations in PBIR reports, including ready templates for matrix and table cells, new card images and per-button images on the new button slicer. Automatically invoke when the user mentions "SVG visual", "DAX sparkline", "SVG measure", "inline graphics with DAX", "ImageUrl data category", "extension measure", or asks to create any DAX-generated chart (progress bars, bullet charts, KPI indicators, data bars, gauges, donut charts, lollipop charts, dumbbell charts, status pills, overlapping bars, boxplots, IBCS bars, jitter plots, box-and-whisker charts).Other plugins' skills for the same job