Skip to content
Tutorials Center
My learning

Topics

Lesson 43 of 56 ยท Visuals and Reports

Custom Visuals, AppSource, and R/Python Scripts

Extend Power BI beyond the built-in charts: AppSource and certified custom visuals, .pbiviz files, R and Python visuals, scripts in Power Query and the limits in the service.

Power BI ships with dozens of visuals, and for most reports they are enough. Sometimes they are not: you need a Gantt chart, a word cloud, a Sankey diagram, a statistical plot, or a chart your company designed. There are three ways to go beyond the built-in set: custom visuals that you add from a marketplace or a file, R or Python visuals where a script draws the picture, and R or Python scripts in Power Query that transform data before it reaches the model.

This lesson explains each option, how to add it safely, and the limits you will meet when you publish. Power BI is a desktop and cloud tool, so the steps are described in words. The runnable examples are Python code of the kind you would paste into a Python visual or a Power Query script, with a short line that builds the dataset the real tool would supply. That line is the only stand-in. The plotting code is exactly what Power BI would run.

Three ways to extend visuals

Three ways to extend Power BI

Custom visual Download from AppSource or import a .pbiviz file.
R or Python visual A script draws a static picture.
Script in Power Query A script cleans or builds data.

Different tools, different limits.

1 / 2

Custom visuals and AppSource

A custom visual is a chart built by Microsoft or a third party with the Power BI visuals SDK (TypeScript and JavaScript). It behaves like a built-in visual: you drag fields into it, format it, filter it, and it takes part in cross-filtering.

To add one in Desktop, open the Visualizations pane, click the three dots (Get more visuals) and search AppSource, the Microsoft marketplace. Click Add and the visual appears in the pane. You can also choose Import a visual from a file and select a .pbiviz file, which is how a visual designed inside your own company is installed. In the service, an administrator can also publish organizational visuals that every report author can pick from a company list.

Certified visuals and safety

Custom visuals run code from someone else inside your report, so the source matters.

Kind What it means
Microsoft visuals Made by Microsoft, tested like built-in ones.
Certified The author submitted the code to Microsoft for a review: no external calls to services outside the visual, no hidden data collection. Certified visuals can be exported to PowerPoint and rendered in email subscriptions, which uncertified visuals cannot.
AppSource, not certified Listed on the marketplace, but not reviewed in the same way; some are free, some are paid.
Imported .pbiviz files Unreviewed code that you trust only as much as its author.

An administrator can limit which visuals may be used in the tenant settings: allow all, allow only certified, or block them. Before you rely on a visual in a report others will use, check three things: who publishes it, whether it is certified, and whether its license allows your use, because some visuals have paid tiers or watermarks in the free version.

Treat a custom visual as a dependency, like a library in software. If the author stops maintaining it, a Power BI update can break it. Keep a note of which pages use which custom visuals, and prefer a built-in visual when it does the job.

R and Python visuals

An R visual or Python visual draws a chart with a script. You add the visual from the Visualizations pane, drag the fields you want into Values, and Power BI hands your script a data frame named dataset (a data.frame in R, a pandas DataFrame in Python). Your script must produce a plot (with plot(), ggplot2, matplotlib or seaborn), and Power BI renders it as an image.

You need R or Python installed locally to develop these visuals in Desktop (set the path under File > Options > Python scripting). In the service, the visual runs on Microsoft's servers with a fixed list of supported packages (for Python: pandas, NumPy, matplotlib, seaborn, scikit-learn and others on a published list), so a package that works on your laptop may be missing there.

Setting up R. Install R from the R Project, then in Desktop open File > Options and settings > Options > R scripting. Power BI lists the detected R home directories (for example the folder where R 4.x was installed) and you choose one, or browse to another. If you use RStudio, set the same path under Detected R IDEs. Install packages you need (such as ggplot2 or psych) in that R installation; the Desktop script visual then loads them with library(). The Python setup is identical but under Python scripting. Restart Desktop after installing a new interpreter.

The facts to remember:

  • The visual is a static image. Readers cannot click elements to cross-filter, but the image is re-drawn when slicers and filters change.
  • The dataset has duplicate rows removed, so include a unique key column (like an ID) if you need every row.
  • Only about 150,000 rows are passed to the script; with more, the visual shows a warning and plots a subset.
  • The script has a time limit of about five minutes, and the service runs it without internet access.
  • The image resolution is fixed (72 dpi), so fine details can look soft.

Try it: a Python visual's script

In Desktop, Power BI creates the dataset variable for you. The first lines below build one so you can run the script here. In a real Python visual, you would delete those lines and keep everything below the comment.

Python A Python visual script (with a stand-in dataset)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In Power BI the printed text would not appear on the visual, only the plot does. We print the total here as a check, which is a handy debugging trick: the Python/R script editor pane at the bottom of the screen also shows errors in red when something fails.

R in short

An R visual is the same idea with dataset as a data.frame:

R
library(ggplot2)
ggplot(dataset, aes(x = Month, y = Sales)) +
  geom_col(fill = "#2b6cb0") +
  theme_minimal()

Power BI cannot run R in this lesson, so this block is read-only. The same rules apply (static image, deduplicated dataset, row limit, supported packages in the service).

Scripts in Power Query

You can also run a script as a transformation step in the Power Query Editor: Transform > Run Python script (or Run R script). Power BI passes the current table as dataset, runs your code, and offers every data frame you create as a new table. The generated M looks like this:

M
#"Run Python script" = Python.Execute(
    "# 'dataset' holds the input data for this script#(lf)dataset['Margin'] = dataset['Revenue'] - dataset['Cost']",
    [dataset = #"Changed Type"]
),
dataset1 = #"Run Python script"{[Name = "dataset"]}[Value]

Scripts in Power Query are for things Power Query steps cannot do: a statistical model, a text algorithm, a call to a library. They are slower than native steps, they break query folding (see Query Folding and Incremental Refresh), and in the service they generally need an extra setup, such as a personal gateway, to refresh. Check Microsoft's current documentation for your tenant. Before you reach for a script, check whether the transformation exists as a step, as in Shaping Columns and Rows or Custom Functions and Parameters.

Try it: a cleaning script that returns two tables

Python Stand-in: a Power Query Python script with two outputs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Power Query would show two tables to choose from, dataset and summary. In the stand-in, Ana appears once after cleaning, because the duplicate check ran after we trimmed and capitalized the name.

Choosing between the options

  • Need a common chart? Check the built-in visuals, then AppSource.
  • Need a statistical or very custom plot? Use an R or Python visual, knowing it is static and package-limited.
  • Need to calculate or clean data? Use Power Query steps, then DAX, and a script only as a last resort.
  • Need the same custom look everywhere? Ask your administrator to publish an organizational visual or a theme, as covered in Formatting, Themes and Report Design.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does the Python visual hand your script?

    The fields you place in Values arrive as a DataFrame called dataset, with duplicate rows removed.
  2. 2. A certified custom visual can do something an uncertified one cannot. What?

    Certification (a Microsoft code review) is what allows export to PowerPoint and rendering in subscriptions.
  3. 3. Readers click a bar in an R visual. What happens?

    R and Python visuals are images. They update when filters change, but the image itself is not interactive.
  4. 4. Why does a Python script in Power Query often hurt refresh performance?

    Native steps may fold into one source query. A script step cannot, so the data is pulled first and processed afterwards.
  5. 5. Which option installs a visual developed inside your own company?

    A .pbiviz file is the package format of a custom visual, and it can be imported from the Visualizations pane.

Summary

  • Add custom visuals from AppSource or a .pbiviz file; prefer certified ones and check the publisher and license.
  • R and Python visuals draw static images from a dataset (deduplicated, around 150,000 rows) and use a fixed package list in the service.
  • Scripts in Power Query transform data, break query folding and usually need extra setup to refresh in the service.
  • Choose built-in features first, then marketplace visuals, then scripts.

Next: Dashboards: Pinning Tiles and Adding Reports in the service lesson, or build a full report in Project: Sales Dashboard.