Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

R Visual - lubridate package not found

Hello,

 

I received a report from a user I need to publish in PBI Service. This report is using R visual and unfortunately my knowledge in R is really limited.

When I publish the report it shows error in the R visual saying that "there is no package called "lubridate"". But I checked on this list () and lubridate is here. So I don't really understand why it doesn't work.

Do you have any idea why this is in error ?

 

Here's the error message and the R visual code :

error_lubridate.PNG

 

.libPaths("\\\\Homedirs\\g32377\\Documents\\R\\win-library\\3.5")
.libPaths()  
library("lubridate")
library("dplyr")
library("ggplot2")
library("tidyquant")

firstyear<-min(dataset$year)
lastyear<-max(dataset$year)
marque<-unique(dataset$MARQUE)

dataset<-dataset%>%
  mutate(DCLOEX2=as.Date(DCLOEX2))

prixtotal<-dataset%>%
  group_by(NUMMIS)%>%
  summarise(totalcost=sum(AM))%>%
  left_join(unique(dataset[,c('NUMMIS','DCLOEX2')]),by="NUMMIS")

prixaverage<-prixtotal%>%
  group_by(date=floor_date(DCLOEX2, "1 year"))%>%
  summarise(average=mean(totalcost))%>%
  mutate(average2=round(average))

nombre<-prixtotal%>%
  group_by(date=floor_date(DCLOEX2, "1 year"))%>%
  count()

pieces12<-dataset%>%
  filter(DCLOEX2<ymd(paste(firstyear+1,01,01)))%>%
  group_by(CODE_clean)%>%
  summarise(total12=sum(AM))

pieces12<-pieces12%>%
  mutate(av12=total12/nombre$n[1])


pieces18<-dataset%>%
  filter(DCLOEX2>ymd(paste(lastyear-1,12,31)))%>%
  group_by(CODE_clean)%>%
  summarise(total18=sum(AM))

pieces18<-pieces18%>%
  mutate(av18=total18/nombre$n[as.numeric(dim(nombre)[1])])

difference<-full_join(pieces18,pieces12,by='CODE_clean')%>%
  select(CODE_clean,av12,av18)%>%
  mutate(av12=ifelse(is.na(av12),0,av12))%>%
  mutate(av18=ifelse(is.na(av18),0,av18))%>%
  mutate(diff=av18-av12)%>%
  mutate(diff2=round(diff))%>%
  arrange(desc(diff))
difference<-left_join(difference,unique(dataset[,c('CODE_clean','label.1')]),by=c('CODE_clean'))

other<-difference[-(1:10),]
nbr<-as.numeric(dim(other)[1])
other<-data.frame('CODE_clean'=paste('others (',nbr,')'),'av12'=sum(other$av12,na.rm=TRUE),'av18'=sum(other$av18,na.rm = TRUE),'diff'=sum(other$diff),'diff2'=round(sum(other$diff)),'label.1'='')

final<-rbind(difference[1:10,],other)%>%
  select(CODE_clean,diff2,label.1)


a<-c(prixaverage$average2[1],final$diff2)
a<-cumsum(a)
open<-a[-length(a)]
close<-a[-1]

graphe<-cbind(final,'open'=open,'close'=close)

lab<-paste(graphe$CODE_clean,graphe$label.1)

order_CODE <- unique(lab)
graphe$lab <- factor(lab, levels = order_CODE)

p<-graphe %>%
  ggplot(aes(x=lab,y=close))+
  ylim(0,max(close)+150)+
  geom_candlestick(aes(open = open, high = close, low = open, close = close)) +
  labs(title = marque, 
      y = "", x = "") + 
  geom_text(aes(label = diff2), vjust = -0.8, size = 4) +
  theme_tq()+
  theme(axis.text.x = element_text(angle = 90, vjust=0.5))+
  geom_text(x=1, y=open[1]-150, label=paste(firstyear,'\n',round(prixaverage$average[1]),'e'),size =4)+
  geom_text(x=11, y=open[11]-150, label=paste(lastyear,'\n',round(prixaverage$average[as.numeric(dim(prixaverage)[1])]),'e'))
print(p)

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @Anonymous,

 

AFAIK, power bi service has its security permission and settings to handle R script and related packages, I don't think 'library path' function can works on service side.

 

Power bi service support lubridate package, I think you can remove 'locate' functions to let r script to detect related resource and packages by itself.

 

Reference links:

 

Creating R visuals in the Power BI service

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.

 

 

R packages in the Power BI service

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @Anonymous,

 

AFAIK, power bi service has its security permission and settings to handle R script and related packages, I don't think 'library path' function can works on service side.

 

Power bi service support lubridate package, I think you can remove 'locate' functions to let r script to detect related resource and packages by itself.

 

Reference links:

 

Creating R visuals in the Power BI service

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.

 

 

R packages in the Power BI service

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors