Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

My Power BI Custom Visual won't work

Hi!

I am trying out a simple example building a Power BI Custom visual. I followed this tutorial https://medium.com/@Konstantinos_Ioannou/how-to-create-an-r-custom-visual-html-for-powerbi-7f2d2e44e453 and every thing seems normal. But when I added my new visual inside Power BI and dragged in two fields from Fields list I got an error that won't go away. I really don't know how to fix this. I have tried many ways from reinstalling all the tools

 

Below you see the error inside Power BI desktop after I have dragged the custom visual into the report area and added the two fields. The script works in R Studio, but my report is failing in Power bi

 

 

Here is my rscript inside the visual studio code project:

 

source('./r_files/flatten_HTML.r')

############### Library Declarations ###############

libraryRequireInstall("ggplot2");
libraryRequireInstall("plotly");

####################################################

################### Actual code ####################
g<-ggplot(datasetaes(x = Pricey = Quantity  )) + 
geom_point(col = "red"alpha = 0.6size = 6) +
theme_minimal()
####################################################

############# Create and save widget ###############
p = ggplotly(g);
internalSaveWidget(p'out.html');
####################################################
 
Beside this an other strange thing happen in my working R script visual in Power BI desktop. For some reason I need to put some code lines like this library("scales", lib = .libPaths()[-1] ) to make it work. I should work without it but it does not. Can somebody explain to me why I must have these code lines to make it work or how to make it work without these lines?
 
# 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(Price, Quantity)
# dataset <- unique(dataset)

# Paste or type your script code here:
library("scales", lib = .libPaths()[-1] )
library("lazyeval", lib = .libPaths()[-1] )
library("plyr", lib = .libPaths()[-1] )
library("tibble", lib = .libPaths()[-1] )
library(ggplot2)
dataset

p<-ggplot(dataset, aes(x = Price, y = Quantity )) +
geom_point(col = "red", alpha = 0.6, size = 6) +
theme_minimal()
p
 
Regards Geir
  • Anonymous's avatar
    Anonymous
    6 years ago

    I am not finished with finding the source of my problems.

    It works in R studio and I have checked that both power bi and R studio run the same version of R. But I found a very interesting link on the web that may be shows the problem. I am checking that out now

     

    https://community.powerbi.com/t5/Desktop/R-Visual-Rcpp-package-error/m-p/488849#M227795

     

    Some below in that page it says:

     

    I had yesterday the same problem. Only reinstalling (or even go back to older versions) did not help.

    Only after I deleted the libraries in "<user>/documents/R" and in "<user>/library"  and reinstalled R and installed the packages I needed, the problem was solved.

     

    I think mixed package versions in <user>/library did give the problem for me. I did not know that packages were also in that directory. Only uninstall R en delete "<user>/documents/R" was not enough.

    The newest version of PowerBi and R (3.5.1) are now working for me.

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI Anonymous,

    According to the error message, it seems like you miss some of R packages so these script formulas not able executed on power bi desktop side. (The package 'XXX' was not installed) You can copy your code to R studio to execute to check and install all required R packages.

    In addition, it looks like you are working with creating a custom visual, I'd like to suggest you post this to develop subforum to get further support.

    Regards,
    Xiaoxin Sheng

    • Anonymous's avatar
      Anonymous
      Not applicable

      I am not finished with finding the source of my problems.

      It works in R studio and I have checked that both power bi and R studio run the same version of R. But I found a very interesting link on the web that may be shows the problem. I am checking that out now

       

      https://community.powerbi.com/t5/Desktop/R-Visual-Rcpp-package-error/m-p/488849#M227795

       

      Some below in that page it says:

       

      I had yesterday the same problem. Only reinstalling (or even go back to older versions) did not help.

      Only after I deleted the libraries in "<user>/documents/R" and in "<user>/library"  and reinstalled R and installed the packages I needed, the problem was solved.

       

      I think mixed package versions in <user>/library did give the problem for me. I did not know that packages were also in that directory. Only uninstall R en delete "<user>/documents/R" was not enough.

      The newest version of PowerBi and R (3.5.1) are now working for me.