Powe R Bi: Enhance Your Microsoft Power BI Experience With R
Powe R Bi: Enhance Your Microsoft Power BI Experience With R
Powe R Bi: Enhance Your Microsoft Power BI Experience With R
Enhance your
Microsoft Power BI
experience with R
As a specialized, open source statistical environment, R represents the primary analysis
language for a large number of data scientists and statisticians. In recent years, R has also
undergone a significant shift in user base by gaining wider adoption in the business world.
your Business Intelligence solutions. In addition to its versatility for data science, R is a great
language and ecosystem for work related to both data visualization and data processing. By
incorporating R into its products, Microsoft has signaled a strong commitment from Microsoft
Over the following pages, you will explore three ways to use R in Microsoft Power BI:
www.blue-granite.com 1
R-powered Custom Visuals
R-powered visuals work like any other Power BI Custom Visual. Apart from requiring a local
connection to R from Power BI Desktop, the use of R in Power BIs R-powered visuals is
hidden from users. They allow users to take advantage of R without knowing R or even
seeing any R code.
If you would like to easily use advanced R visualizations, you can use what other developers have created. Examples include
plotting the correlation between different fields, different types of clustering, advanced forecasting, and more.
Developers use the same tools to create R-powered visuals as they do for standard Power BI Custom Visuals. In fact, most of
the code used to create R-powered visuals often will not be R. It will be TypeScript! Anyone who wants to create R-powered
visuals embeds the R code to visualize data within the Custom Visual framework. Additional code for handling data and
format options utilizes TypeScript.
www.blue-granite.com 2
Acquiring R-powered visuals
Obtain R-powered visuals from the Office Store as you would with any
Power BI Custom Visual. Navigate to https://store.office.com and find
Power BI in the menu.
All
Excel
OneNote
Outlook
Power BI
PowerPoint
R-powered Visuals will display Built with R with the R logo next to it.
For example, see the difference between the Histogram Chart and the
Correlation Plot. The Histogram Chart is a standard custom visual while
the Correlation Plot is R-powered.
After finding your desired R-powered Visual in the Office Store, select it.
A new page appears that shows an Add button to download the visual.
www.blue-granite.com 3
Acquiring R-powered visuals ...continued
PowerBI-visuals-corrplot.1.0.1.0.pbiviz PowerBI-visuals-corrplot.1.0.1.0.pbix
On the left will be an option to Select to Download. After To the right, you may see an option to Try a Sample. If
clicking that, your browser may prompt you to download you select this option, you can download a PBIX report
a PBIVIZ file, or it may automatically start downloading to file, which you can open in Power BI Desktop.
your default download folder.
www.blue-granite.com 4
Using R-powered Visuals in Power BI Desktop
To use Power BIs R-powered Visuals in Power BI Desktop, make sure that you have a version of R installed on your
workstation. You can download R from https://www.r-project.org, or you can use Microsoft R Open and download it from
https://mran.microsoft.com/download.
Power BI Desktop should automatically locate your local R installation, but you can be certain by visiting
File gOptions and SettingsgOptionsgR scripting.
www.blue-granite.com 5
Using R-powered Visuals in Power BI Service
To use R-powered visuals in Power BI Service at https://www.powerbi.com, you do not need R installed on your local
workstation. Simply import the appropriate pbiviz file in the Visualization area as you do in Desktop. Click the [] icon,
select Import a custom visual, and browse for the pbiviz file.
www.blue-granite.com 6
R Visual
What if you want to do more with R than what the R-powered Visuals allow? In this case, use
the built-in R Visual. If you have experience plotting with R or are inspired by the ability to
expand Power BIs native data visualization capabilities, the R Visual is for you.
www.blue-granite.com 7
Using R Visuals in Power BI Desktop
As with R-powered Visuals, Power BI Desktop requires a local version of R to render R Visuals. You can download R from
https://www.r-project.org, or you can use Microsoft R Open and download it from https://mran.microsoft.com/download.
Power BI Desktop should automatically locate your local R installation and any default R development environment. There
is no additional configuration necessary to use a local version of R. For example, you do not need to run a special package
such as Rserve to access R from Power BI. If needed, however, you may configure a setting if you have multiple versions of R
installed locally and want to change which version Power BI uses.
Once you add your data, Power BI prepares a data frame, which is
a two-dimensional R data structure consisting of rows and columns.
In your subsequent code, reference the name of Power BIs initial
data frame, which defaults to dataset automatically.
library(corrplot) As an example, you could add a correlation plot similar to the one
provided by the R-powered Visual of the same name. Provide the code
M <- cor(dataset)
to the R Visual and click the Run Script icon in the top right corner.
corrplot(M) Run Script looks like a play button and appears as the leftmost icon.
www.blue-granite.com 8
Using R Visuals in Power BI Desktop ...continued
To work with R in Power BI Service, users will need a Power BI Pro subscription with a managed tenant. With a Pro license,
R Visuals should render in your reports as well as any dashboard tile to which you have pinned your R Visual.
Unlike with Power BI Desktop, there are some additional limitations when using the R Visual in Power BI Service. The
most noticeable constraint is which R packages are supported. If you use R in Power BI Desktop and need a package that
is not currently available to your workspace, you can simply install it. With Power BI Service, however, there is no way to
install additional packages, but you can request them from the Power BI team for potential future inclusion. Microsoft has
excellent documentation on what packages it supports in Power BI Service. You can find more detail about what packages
are supported by navigating to https://powerbi.microsoft.com/en-us/documentation/powerbi-service-r-packages-support/.
www.blue-granite.com 9
R Script
In addition to using R for data visualization, Power BI can execute R scripts for data
processing tasks. Complementing its native Power Query / M functionality, Power BI
includes a Run R Script option. While Power BI natively handles many advanced data
processing tasks, users may still prefer using R Scripts for a few different reasons. These
may include performing advanced analytics with R or overcoming feature gaps such as
Power BIs lack of regular expressions.
Creating R Scripts requires Power BI Desktop. Reports that use R Scripts can be deployed to Power BI Service, but it requires
the additional use of the Power BI Personal Gateway to refresh R Scripts that reference on-premises data sources.
www.blue-granite.com 10
Using the R Script to Import or Modify Data
R Script appears as an option in Get Data. While Power BI has many data connectors, R may help overcome some issues
getting data from specific formats. For example, if a user has data stored in format used by statistical applications such as SAS
or SPSS, its not easy to get to that data using native Power BI connectors. It is easy to import it using the R Script option.
www.blue-granite.com 11
Using the R Script to Import or Modify Data ...continued
In addition to loading data, the R Script works downstream. You can load data with Power BIs native connectors to get
data from numerous sources that it would be difficult to obtain with R (such as Microsoft Azure connectors). Once youve
connected to that data source and brought data in, however, you can still enrich that data with R.
R
Run R
In the Transform tab, the Run R Script option allows you to execute scripts on existing queries.
Want to do additional data preparation that is difficult or impossible to do in Power BI (such
as use regular expressions)? Want to perform machine learning tasks such as clustering or
Script classification? With R in Power BI, its all at your fingertips!
Final Thoughts
The abundant ways to use R in Power BI help enhance your data and
empower your visualizations. Whether you have broad experience or
no experience with R, incorporate R into your reports. Whoever your
audience, you can tap into the Power of R in Power BI.
Interested in More?
BlueGranite has a quick tutorial on using both the R Script and R
Visual in Microsoft Power BI. Check it out for free online to work
through the hands-on example!
VIEW TUTORIAL