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 in Power BI by Phalguni
• 1,010 points

edited May 22 by Omkar 63 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!!

answered May 21 by Avantika
• 1,500 points

edited May 22 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 in Power BI by Phalguni
• 1,010 points
41 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 in Power BI by Phalguni
• 1,010 points
103 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 in Power BI by Phalguni
• 1,010 points
96 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 in Power BI by Avantika
• 1,500 points
39 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,060 points
92 views
0 votes
1 answer

Unable to install connector for Power Bi and PostgreSQL

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

answered Aug 21, 2018 in Power BI by nirvana
• 3,060 points
708 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
• 15,620 points
126 views
0 votes
1 answer

Connect power bi desktop to dataset and create custom reports

Yes using Power BI REST API to ...READ MORE

answered Sep 18, 2018 in Power BI by Kalgi
• 41,760 points
126 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 8 in Power BI by Avantika
• 1,500 points

edited Mar 9 by Avantika 73 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 in Power BI by Avantika
• 1,500 points
38 views