R Chart cannot be displayed due to a dependency not being available
Hi there.
I'm trying to display an R visual using the code below, but I keep getting told that there is a dependancy issue, a missing component. Unfortunately, it does not tell me which one it is. I do apologies in advance if this is a newbie error.
Basically the code using a field in a database row in order to say whether or not to display a thumbs up or thumbs down image.
#load libraries
library(png)
library(grid)
library(ggplot2)
# get the url string from the imported data frame. Convert it to a character vector.
urlstring <- as.vector(dataset[1,1])
# if you use an image URL, you have to download the file first:
z <- tempfile()
download.file(url = urlstring,destfile = z,mode="wb")
#read the PNG image file
pic <- readPNG(z)
# create a raster of the PNG file
g<-rasterGrob(pic,interpolate=TRUE)
# create a plot and add the image
p <- qplot(1:10,1:10,geom="blank") + annotation_custom(g,xmin=-Inf,xmax=Inf,ymin=-Inf,ymax=Inf)
# remove all clutter from the plot and display it
p + theme(axis.line=element_blank(),axis.text.x=element_blank(),
axis.text.y=element_blank(),axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),legend.position="none",
panel.background=element_blank(),panel.border=element_blank(),panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),plot.background=element_blank())
7 Comments
- v-qiuyu-msft
Community Support
Hi jigr69,
The R script you provided works fine on my side. You can download our test report to test in your environment. Please run the Power BI desktop version 2.49.4831.521.
Best Regards,
QiuyunYu - Vicky_Song
Impactful Individual
Status changed:NewtoNeeds Info - jigr69Frequent Visitor
Hi there.
I admit to missing out one important point in my OP, that was that it works fine on the Power BI Desktop, but not on the Power BI Service.
Whoops my bad.
Cheers
- v-qiuyu-msft
Community Support
Hi jigr69,
Based on my research, this is due to the package "Grid" is not supported in Power BI service. You can see this this article: R packages that are supported in Power BI.
Best Regards,
QiuyunYu - jigr69Frequent Visitor
Considering that Grid is part of the base packages of R, I'm surprised that it is being excluded by Microsoft. I know Microsoft has included gridBase and gridExtra, but neither contain the function rasterGrob which my script relies on. I also believe that the latest versions of ggplot2 depended upon grid and as such, were included.
Does anyone know of a replacement function that is available in gridBase or gridExtra?
- AnonymousNot applicable
Any work-around/solution on this? Our customer developed a PBI Desk top R visual with three libraries and failed running in it powerbi.com, thus the report cannot go to prod. Please help.
- AnonymousNot applicable
RESOLVED
We talked to Bois Efrady, Microsoft PBI R expert, and was informed that the root cause of this problem is that currently the URL retrieving is blocked in PBI R scripting. So a work-around is to encode PNG into Base64 string and then decode it into readPNG(). Here is the sample which displays a small Yen sign.
library(png)
library(base64enc)tempNamePNG = "tempPNG.png"
#here is the string (copy-pasted manually after convertion at https://www.base64-image.de/encode)
oneLine_cha_data_back <- "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAAdFJREFUWMPll79Lw0AUxzMWpw4iKKKHIAZcblQQDBScBLu6VRwj2FFcblOEThYnwfwBLm4OHSounaSruBRcHTo4OZ3vW1KJyTvJpWdrMfCB8u77vnyb+5HE01p7k8T7UwHGdU1FgBLRICKGE4PvTz2NeDx3gEa9XtdKqQy1Wg3CFhOgZepBPQ5hF8B0CSEgriT0FSmlUV8kAG6X7vVeqPyRIYquIe4k9B3UOC084GU7Bbia1eould9ZhFga3oUKfpt08IBX0V3Qb7fvaOgtQxQ1h3ehg9+cBr3wGGUbhlKu09ArixCLA0zjQbAJ03DUc4D+4TkNP2dQ6kibxlBPrZPCAWiOF3S//0CSp2+gxtUBelI7xTpAGM/fAKUOSPKYC2iTvelpyBNgS8oVWkQXX3S7VyS5zwW0yV54wdMmQDUIsPhunQAveFoG8Kl04wR4FQiwSqVLJ8DLNoAXP3A0h9ZnLCZ9+uGVJ8BsuVyi5MssWp+ymPTwgqflFOCEO3YCvAqsgXkqHToBXgUCzFFp3wnwsg3gCzFDJ9oai9Z7LCY9vOBpuwt8w/sdSXdY4hXP9fgu34pJus0SB/j113KSbrCMK0Ar74Ez1R8mkwnwL7+OPwFmauaESwFeIAAAAABJRU5ErkJggg=="#decode string
binDataBack = base64decode(oneLine_cha_data_back)#write decoded to png
to.write = file(tempNamePNG,"wb", raw = T)
writeBin(binDataBack,con = to.write)
close.connection(to.write)#
img1 <- readPNG(tempNamePNG)
grid::grid.raster(img1)Hope this helps.