
Creating R Visuals in Power BI Desktop
A while ago, I came across an error message similar to the one I will be discussing in this post. You will learn how to create R Visuals in Power BI Desktop using the R Script visual.
- Before creating the visual you have to ensure that the Detected R home directories on Power BI Desktop matches your local R installation path and version. For this example, I have R-3.4.3 installed, so my Detected R home directories
from File -> Options and settings -> Options -> R Scripting should look like this: C:\Program Files\R\R-3.5.3

2. Once the directory is confirmed, import your data into Power BI via Get Data and select the R visual under visualizations.

You will be Presented with R Script editor where you can add your Script.

3. Select the data from the fields section as seeing below

When you select the data, a dataframe is automatically created for you in Power BI called dataset. You may receive an error similar to the one below if you use a different name for your dataframe other than the dataset that is automatically created when you select your data.

4. For this example we will be using the correlation matrix visual so, ensure that you have the corrplot package installed in R and paste your R Script:
# dataset <- data.frame(Crime, Ineq, LF, M, M.F, NW, Po1, Po2, Pop, Prob,S1) # dataset <- unique(dataset)
require(“corrplot”) library(corrplot)
mydata <-cor(dataset)
corrplot(mydata,method = “color”, tl.cex = 0.6, tl.col = “red”, type=”upper”, outline = T, number.digits = 1, number.cex = 0.7, cl.pos = ‘b’, insig=”blank”, addCoef.col = “black”)

You can use a slicer or another visual to filter or interact with R visual in Power BI but the image by itself is not interactive. Here is another example that shows how to interact with R visuals :

