Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

dir.create in R is not working for Power BI service.

Hi,

 

I have a R visual which creates a directory in your local using dir.create(C:/foldername) and it is working fine in Power Bi desktop but same when deployed in Power Bi service, it is throwing me an error like C:/foldername does not exist. That means it is not creating directory. 

 

Could you please help me fix the solution for this.

 

Thanks,

Shubham

  • Hi Anonymous ,

     

    Sorry for the delay. I may misunderstand your scenario before.

     

    By my research for your sceanrio, I'm afraid that we cannot show your desired output in Power BI Service based on R scripts security.

     

    • R visuals are created from R scripts, which could potentially contain code with security or privacy risks.
    • These risks mainly exist in the authoring phase when the script author run the script on their own computer.
    • The Power BI service applies a sandbox technology to protect users and the service from security risks.
    • This sandbox approach imposes some restrictions on the R scripts running in the Power BI service, such as accessing the Internet, or accessing to other resources that are not required to create the R visual.

    Best  Regards,

    Cherry

4 Replies

  • v-piga-msft's avatar
    v-piga-msft
    Resident Rockstar

    Hi Anonymous ,

     

    By my tests with the latest version of Power BI Desktop, it seems that everything works as expected.

     

     

    Here is my setting.

     

     

    If you still need help, please share a dummy pbix file which can reproduce the issue, so that we can help further investigate on it? You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading.)

     

    You also could have a test with my test pbix file.

     

    Best  Regards,

    Cherry

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks v-piga-msft  for your reply.


       

      My code works in a following : - first it will create a directory if it does not exists. then if it exisits then Message will be printed as  "Folder exists" else Message will be printed as "Folder does not exists". Ideally it should never go into else part because i am creating my direcory in the first line.

      It does work fine in Power BI desktop as you can see the result in the above image itself.

      When i publish to Power BI services, it does not creates the directory and falls in to the else part. Please find below image :

       

      Please find the below full R code and can you please replicate the same. Just copy-paste it into R visual script and pass 1 dummy column. It will be very helpful for me.

      # Sheet name
      ExportSheet    =  "Sheet 1"
      # Appends data to existing file or overwrites existing fle
      AppendToPreviousFile  = FALSE
      # Includes header. Better to set to false if AppendToPreviousFile is TRUE
      WithHeader    = TRUE  
      
      ### Export functions ##################################################################################
      
      Message <- function(Text,Comment) { 
          
          par(mar=c(1,1,1,1)) 
          NoPlot = c(0) 
          barplot(NoPlot)
          plot(1:1, 1:1, main = "", sub = "", fg="white")
          text(1, 1.2, Text, cex = 2, fg="white")
          text(1, 0.8, Comment, cex = 1.5, fg="white")
          return()
      }
      ExportFile   = "C:/RData/AssetData.xlsx"
      dir.create("C:/RData/")  #This creates a folder if not exists
      ExportFolder = dirname(ExportFile)
      if (dir.exists(ExportFolder)){     #If folder exists then execute below code
          Message("Folder  exist",ExportFolder)
      } else {                           #else
          Message("Folder does not exist",ExportFolder)
      }

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        v-piga-msft  Could you please replicate the same and see if it is possible to solve or not. I really need help on this. 

         

        Thanks in advance.