cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Vmartin002
Frequent Visitor

R-Script Visual Runtime Error in Power BI Server

Hi Everyone, 

 

I wrote a R-Script that works/runs perfectly in Power BI Desktop but doesn't work when published to the Power BI Service. I'm not able to pinpoint the error, is it the pipe operator (%<%)? Any help would be highly apperciated, I've been struggling with this issue for some time now.  Script Runtime Error: Evaulation Error: Level sets of factors are different

 

Error_R.PNG

 

R-Script:

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:

# dataset <- data.frame(ProjectName, Commodity, WBS_code, Months, Running_Total_V2, Total_Scope_V2, RTPercentCompleteV2, Project_Description)
# dataset <- unique(dataset)

# Paste or type your script code here:
library(dplyr)
library(ggplot2)
library(RColorBrewer)


proposal_project <- unique(dataset[["Project_Description"]])

# there are duplicates due to WBS
df <- dataset %>% select(ProjectName, Commodity, Months, RTPercentCompleteV2) %>% distinct()

# for projects with multiple entries for the same percent complete, keep the highest value
df <- df %>% group_by(ProjectName, Commodity, RTPercentCompleteV2) %>% slice(which.max(Months)) %>% arrange(Months)

# group by and interpolate
pctcomplete <- seq(0.1, 1, by=0.05)
df <- df %>% group_by(ProjectName, Commodity) %>% group_modify(~ {approx(.x$RTPercentCompleteV2, .x$Months, xout=pctcomplete) %>% data.frame()}) %>% ungroup()
prop_df <- df %>% filter(ProjectName == proposal_project) # split out proposal data after transformations
df2df <- df %>% filter(ProjectName != proposal_project)


data_wo_proposal <- df2df %>% group_by(Commodity,x) %>% summarise_at(vars(y),list(mean_duration = mean))

# plot
mindiff <- min(c(0))
maxdiff <- max(c(max(data_wo_proposal$mean_duration, na.rm=TRUE), max(prop_df$y, na.rm=TRUE)))
ticks <- round(seq(mindiff, maxdiff, by=2))
tick_y <- seq(0,100, by=5)

g <- ggplot(data=data_wo_proposal, aes(x=mean_duration, y=x, colour=Commodity)) + geom_line(linetype=2) + geom_point()
final_plot <- g + geom_line(data = prop_df, aes(x=y,y=x,colour=Commodity)) + geom_point(data=prop_df,aes(x=y,y=x,colour=Commodity))
final_plot_label <-
final_plot + labs(title='Average Duration of Reference Projects vs Proposal Project', subtitle=paste('Proposal Project:',prop_df$ProjectName[1], '(solid line in figure below)'), x= 'Duration (Months)',y='Percent Complete') + theme_bw() + theme(legend.position='bottom', legend.title=element_blank()) + scale_colour_brewer(palette='Set1') + scale_x_continuous(breaks=ticks)+scale_y_continuous(labels = scales::percent_format(accuracy = 1),breaks=seq(0,1, by=.05))
final_plot_label

 

 

Thank you,

Val

1 ACCEPTED SOLUTION

Update:

 

I was able to figure out the issue with the R-Script Visual on the Power BI Service.

 

The level of factors was fixed by the following edits:

Orginal:
prop_df <- df %>% filter(ProjectName == proposal_project) 
df2df <- df %>% filter(ProjectName != proposal_project)
New:
prop_df <- df %>% filter(as.character(ProjectName)== as.character(proposal_project))
df2df <- df %>% filter(as.character(ProjectName) != as.character(proposal_project))
 
Also, make sure the package versions are up to date according to https://docs.microsoft.com/en-us/power-bi/connect-data/service-r-packages-support there happened to be unsupported function "group_modify" not supported by the approved dplyr package. Lastly, there seems to be some discrepancies with package versions. To ensure your R-script will run on the power BI service make sure your local machine is running Microsoft R 3.4.4 or R 3.4.4. This is the same R enviroment used on the cloud, so if it runs on your desktop with this version it will run on Power BI service. Also, use install.packages("_____") in your R-Terminal since this will allow package versions that are supported on R 3.4.4. this will help avoid ambiguity.
 
Best of luck!
Val

View solution in original post

2 REPLIES 2
winceeS
Regular Visitor

Hi, R Visual is currently not supported in Power BI Report Server. it's only available in PBI Service.

checkout the  documentation.

https://docs.microsoft.com/en-us/power-bi/report-server/compare-report-server-service

Update:

 

I was able to figure out the issue with the R-Script Visual on the Power BI Service.

 

The level of factors was fixed by the following edits:

Orginal:
prop_df <- df %>% filter(ProjectName == proposal_project) 
df2df <- df %>% filter(ProjectName != proposal_project)
New:
prop_df <- df %>% filter(as.character(ProjectName)== as.character(proposal_project))
df2df <- df %>% filter(as.character(ProjectName) != as.character(proposal_project))
 
Also, make sure the package versions are up to date according to https://docs.microsoft.com/en-us/power-bi/connect-data/service-r-packages-support there happened to be unsupported function "group_modify" not supported by the approved dplyr package. Lastly, there seems to be some discrepancies with package versions. To ensure your R-script will run on the power BI service make sure your local machine is running Microsoft R 3.4.4 or R 3.4.4. This is the same R enviroment used on the cloud, so if it runs on your desktop with this version it will run on Power BI service. Also, use install.packages("_____") in your R-Terminal since this will allow package versions that are supported on R 3.4.4. this will help avoid ambiguity.
 
Best of luck!
Val

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power BI October Update 2021.jpg

Power BI Release

Click here to read more about the October 2021 Release!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Teds Dev Camp Oct. 2021 768x460.jpg

Power BI Dev Camp - October 28th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors