Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Administrator
4 years ago
Solved

Issues with R scripts in Power BI

stimada community,

I've been trying to use the R script visual in power BI to work with some R visualizations. I've watched over 3 videos to use these R scripts, but I have a basic problem that won't let me move forward.

In the image below you can see that I have uploaded 3 columns from a database to the R script, but these are not automatically loaded to the R script as is often the case in all the videos I have seen.

AlexisCab1602_0-1631219126593.png

This is an example of what should happen when loading the columns to the visual, in the R script the dataset is automatically updated with the contents of the different columns.

AlexisCab1602_1-1631219195505.png

I leave you the information of my R script configuration

AlexisCab1602_2-1631219337190.png

What am I doing wrong?

Stay tuned, thank you very much.

8 Replies

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Administrator

      If I delete only the # of line 3 it looks like this

      AlexisCab1602_0-1631220768234.png

      Columns added to the visual are still not added to the data.frame. Now, if I remove the entire line 3

      AlexisCab1602_1-1631220830189.png

      nothing happens either, I just run out of my data.frame. I don't understand why the data.frame doesn't update automatically when you add columns to the visual. What do you recommend I try?

      • v-janeyg-msft's avatar
        v-janeyg-msft
        Community Support

        Hi, Syndicate_Admin 

         

        Logically speaking, if the R script is successfully installed, it should be automatically generated. So I consider whether the version you installed is too high and powebi doesn't support it.

        You can try to download the lower version.

        Reference:

        Learn which R packages are supported - Power BI | Microsoft Docs

        Did I answer your question ? Please mark my reply as solution. Thank you very much.
        If not, please feel free to ask me.


        Best Regards,

        Community Support Team _ Janey

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Administrator

      I've done the tutorial you sent, and it works, but not as I expected.

      AlexisCab1602_0-1631562195435.png

      If you look at code line 3, I have manually added "dataset <- data.frame()" and within this I have not added any of the columns that appear in the visual on the right. Still, the code works, but I still do not understand the reason why the dataset is not created automatically with the columns that I am adding, it is a strange problem but at least now I can use some R libraries in Power BI. Thank you very much for the link, if you have information regarding why the dataset is not automatically generated I would appreciate it.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi ,

     

    I hope you can help me with the problem I have Re R scripting which is similar to this track 

     

    I have  succesfully run many R scripts both in power Bi and the service.

     

    My main problem is reading in RDS image file or even RDS csv compressed files in the service ..the sites are open public Github sites .. all code works in the desktop ..even reading from all the github sites  IN THE VISUAL R SCRIPTS . But when I run it in the service to the same sites it keeps saying the following

     

    with the following code in the R visual :

     

     
     
    I get the following error

     

    Error in gzfile(file, "rb") : cannot open the connection In addition: Warning message: In gzfile(file, "rb") : cannot open compressed file 'https://github.com/gbortz27/aizatron/blob/main/mytitanic.rds?raw=true', probable reason 'No such file or directory exists"

     

    OR with this code 

     

     

    url4="https://github.com/gbortz27/aizatron/blob/main/mytitanic.rds?raw=true"
    
    #data <- readRDS(url(url4, method="libcurl"))
    
    #data=readRDS(gzcon(url(url4)))
    
    data=read_rds(url4)
    
    ggplot(data,aes(x=Age,y=Fare)) +geom_point()

     

     

     

    url4="https://github.com/gbortz27/aizatron/blob/main/mytitanic.rds?raw=true"
    
    data <- readRDS(url(url4, method="libcurl"))
    
    #data=readRDS(gzcon(url(url4)))
    
    #data=read_rds(url4)
    
    ggplot(data,aes(x=Age,y=Fare)) +geom_point()

     

     

     

     
     
    I get this error

    Script Runtime Error

    Attaching package: 'dplyr' The following objects are masked from 'package:stats': filter, lag The following objects are masked from 'package:base': intersect, setdiff, setequal, union Loading required package: bitops Error in readRDS(url(url4, method = "libcurl")) : cannot open the connection to 'https://github.com/gbortz27/aizatron/blob/main/mytitanic.rds?raw=true' In addition: Warning message: In readRDS(url(url4, method = "libcurl")) : URL 'https://github.com/gbortz27/aizatron/blob/main/mytitanic.rds?raw=true': status was 'Couldn't resolve host name'
    However when it comes to reading in the file from getdata in the R script I can read  in both RDS (compressed csv)  and csv files and process them in the Query editor FROM THE EXACT SAME URLS. So if thr Rscript in the Get data IN THE SERVICE is working from the same sites it should mean there is no problem with 
     
    1) the versions of R in the service 
    2) the access to the sites 
     
    So why is the R visual script different to the Get data R script engine.
     
    So one may ask , well then bring the data in via the Get Data script.
     
    The problem is if its a ggplot image (compressed in RDS format)  , although it reads in the file (the compressed RDS Image ) it displays as a "blob" for want of a better word and I dont  know how to decompress the image in the Query editor ie unserialize the rds file into a data frame  , bring it into the R visual , and resconstruct the image in the visual R script.
     
    One may ask :: why are you not generating the ggplot image from the raw data.
     
    For 3 reasons: 
     
    1) the absence of libraries in the service , for instance ..tidymodels, ggstatsplot and many others
    2) the libraries in the service are outdated , specifically ggplot2 (one of the most popular libraries in R) 
    3) the limited time give for the R visual to process
    4) Size of Graphics
     
    One may also ask that why cant you store them as png.. because RDS files can be stored in such as way as to make them interactive via another dataframe brought in independently. 
     
    So in conclusion there is something different between the Rscripting in Get data and the R scripting in the R visual as per the access to github files. 
     
    Is there an issue with my code ie should I change the readRDS parametres in the visual or it it some security setting in the Service that prevents access to the site.
     
    I have also loaded the Github app and given the srrvice permission the access files in my public repository. It connected to the repository as it showed the my dashboard..but this made no difference to the success of accessing the data.
     
    • v-janeyg-msft's avatar
      v-janeyg-msft
      Community Support

      Hi Anonymous 

       

      This thread has been solved. If you have problems and are more complicated, I suggest you open a new thread. There will be other engineers to help you.

       

      Best Regards,

      Community Support Team _ Janey