How to use R script in Power BI

In this post, I have embedded the video link to my you tube channel and in the video I have showed how to use R script in Power BI. I have also posted below the scripts shown in the video.

In the video, I have explained:

1)How to R script in Power BI
2)Example dataset - COVID-19 (2019-nCoV) github data repository by Johns Hopkins University. How to invoke this data dynamically using Rcurl.
3)How to configure to specific R version in R Studio & Power BI

4)Sample visualization in Power BI using R dataset






How to use R script in Power BI
--To enable external scripts execution
EXEC sp_configure  'external scripts enabled', 1
RECONFIGURE WITH OVERRIDE

--To print R version
EXECUTE sp_execute_external_script @language = N'R'
    , @script = N'print(version)';
GO

--To list all R packages installed

EXEC sp_execute_external_script @language = N'R'
    , @script = N'
OutputDataSet <- data.frame(installed.packages()[,c("Package", "Version", "Depends", "License", "LibPath")]);'
WITH result sets((
            Package NVARCHAR(255)
            , Version NVARCHAR(100)
            , Depends NVARCHAR(4000)
            , License NVARCHAR(1000)
            , LibPath NVARCHAR(2000)

            ));

R Script used in power BI:
library(RCurl)

dt <- format(as.Date(Sys.time())-1, "%m-%d-%Y")
uri1 <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/"

uri <- paste0(uri1,dt,".csv")

rawdata <- getURL(uri)

convidds <- read.csv(text = rawdata)


See Also:

My other posts on Power BI

SQL Server Import/Export excel using R





No comments: