How do you run R script visual in Power BI Service

0 votes

I have created a R visual that loads data and makes a calendar. The following script is working fine in Power BI Desktop but not in Power BI Service
This is the error which I am getting:

as.POSIXlt.default(x, tz = tz)

I don't know how to convert 'x' to class "POSIXlt"
Date is just a table of dates:

Date:

2019-01-14
2019-01-15
2019-01-16
2019-01-17
2019-01-18

library(ggplot2)

p <- ggplot(dfr,aes(x=week,y=day))+geom_text(aes(label=paste(ddate,sep ="")))+scale_fill_manual(values=c("#8dd3c7","#ffffb3","#fb8072","#d3d3d3"))+facet_grid(~month,scales="free",space="free")+labs(x="Week",y="")+theme_bw(base_size=12)+theme(legend.title=element_blank(),

panel.grid=element_blank(),

panel.border=element_blank(),

axis.ticks=element_blank(),

strip.background=element_blank(),

legend.position="top",

legend.justification="right",

legend.direction="horizontal",

legend.key.size=unit(0.4,"cm"),

legend.spacing.x=unit(0.3,"cm"))

plot(p)
May 21, 2019 in Power BI by Phalguni
• 1,020 points

edited May 22, 2019 by Omkar 1,425 views

1 answer to this question.

0 votes

Hi,

It seems that your data format not recognized correctly if you use Power BI Service. Please refer code functions to convert these date values :

library(ggplot2)

dfr <- dataset
dfr$day <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%A"),levels=c("Sunday","Saturday","Friday","Thursday","Wednesday","Tuesday","Monday"))
dfr$week <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%V"))
dfr$month <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%B"),levels=c("January","February","March","April","May","June","July","August","September","October","November","December"))
dfr$ddate <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%d"))

# plot
p <- ggplot(dfr,aes(x=week,y=day))+
geom_text(aes(label=paste(ddate,sep ="
")))+
scale_fill_manual(values=c("#8dd3c7","#ffffb3","#fb8072","#d3d3d3"))+
facet_grid(~month,scales="free",space="free")+
labs(x="Week",y="")+
theme_bw(base_size=12)+
theme(legend.title=element_blank(),
panel.grid=element_blank(),
panel.border=element_blank(),
axis.ticks=element_blank(),
strip.background=element_blank(),
legend.position="top",
legend.justification="right",
legend.direction="horizontal",
legend.key.size=unit(0.4,"cm"),
legend.spacing.x=unit(0.3,"cm"))

plot(p)

Hope This Helps!!

Ready to elevate your data skills? Dive into our Power BI Course Content and embark on a transformative learning journey designed for data enthusiasts, analysts, and business intelligence professionals!

answered May 21, 2019 by Avantika
• 1,520 points

edited May 22, 2019 by Omkar

Related Questions In Power BI

0 votes
1 answer

How do you create visualizations in Power BI?

Visualizations in Power BI Visuals are the end-result ...READ MORE

answered Feb 27, 2019 in Power BI by Phalguni
• 1,020 points
614 views
0 votes
1 answer

How do you add a slicer from different table in Power BI?

In order to add a slicer from ...READ MORE

answered Mar 5, 2019 in Power BI by Phalguni
• 1,020 points
1,253 views
0 votes
1 answer

How do you embed dashboard using JavaScript in Power BI?

Dashboards in Power BI can be embedded ...READ MORE

answered Mar 5, 2019 in Power BI by Phalguni
• 1,020 points
1,682 views
0 votes
1 answer

How do you schedule Data Refresh in Power BI?

Hi, Following could be the reasons why this ...READ MORE

answered May 21, 2019 in Power BI by Avantika
• 1,520 points
661 views
0 votes
1 answer

Is it possible to use R Plotly library in R Script Visual of Power BI?

For newer versions of PowerBI, it's also ...READ MORE

answered Dec 8, 2020 in Power BI by Gitika
• 65,910 points
1,311 views
0 votes
1 answer

Displaying Table Schema using Power BI with Azure IoT Hub

Answering your first question, Event Hubs are ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
977 views
+1 vote
1 answer

Unable to install connector for Power Bi and PostgreSQL

I think the problem is not at ...READ MORE

answered Aug 22, 2018 in Power BI by nirvana
• 3,130 points
2,433 views
+2 votes
2 answers

Migrate power bi collection to power bi embedded

I agree with Kalgi, this method is ...READ MORE

answered Oct 11, 2018 in Power BI by Hannah
• 18,570 points
1,101 views
0 votes
1 answer

How do you create a link visual in Power BI?

You can easily create a link between ...READ MORE

answered Mar 9, 2019 in Power BI by Avantika
• 1,520 points

edited Mar 9, 2019 by Avantika 4,323 views
0 votes
1 answer

How do you use R visuals in Power BI Desktop?

Hi, In order to use R Visuals you ...READ MORE

answered Apr 10, 2019 in Power BI by Avantika
• 1,520 points
430 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP