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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Nivi_N_26
Regular Visitor

Need help in Finding an Alternative Visual for R- Script visual in Power BI

Hello ,

I am having a R-script visual in my report wherein, it has four columns of X- axis in a date/time format like (Shceduled start, Scheduled End , Actual Start and Actual End) which showcase the project scheduled start and end time with actual start and end time.
Our data connection mode is  direct query for live data , as we all know direct query and r-script together have lot of limitations mentioned in the below documents like can use only limited functions and calculation exceeds timeout error etc...
Use DirectQuery in Power BI Desktop - Power BI | (microsoft.com)
Create Power BI visuals using R - Power BI | Microsoft Learn

In my report am facing very often slow performance issue and script time out error, so am looking for help to find a alternative visual which replace my current R-script visual.R- script Image.JPG
In the above given visual my Y -axis defines the Project name, and the X-Axis defines the scheduled and Actual start and end time with colour code.
R script used

 

 

library(ggplot2)
library(scales)  # For date_breaks and date_format 

# Assuming 'dataset' is already loaded

# Convert time data
time_fields <- c("LocalScheduledStartTime", "LocalScheduledEndTime",
                 "LocalActualStartTime", "LocalActualEndTime")
for (field in time_fields) {
  dataset[[field]] <- as.POSIXct(dataset[[field]], format = "%Y-%m-%dT%H:%M:%OS")
}

# Pre-compute colors to speed up the plot rendering
dataset$status_color <- with(dataset, ifelse(Status == "Completed-On Time", "#0DE018", # Green
                                             ifelse(Status == "Completed-Delayed", "#FFA500", #orange 
                                                    ifelse(Status == "In Progress - On Time", "#FFFF00", #Yellow
                                                    "#FF0000"))))# Red

# Pre-format PercentCompleted
dataset$PercentCompleted <- paste0(sprintf("%.0f", dataset$PercentCompleted), "%")

# Create the ggplot object
plot <- ggplot(dataset, aes(x = ScheduledStartTime, y = TaskName)) +
  geom_segment(aes(x = ScheduledStartTime, y = TaskName,
                   xend = ScheduledEndTime, yend = TaskName),
               size = 8, color = "#9F9D9D") + #Grey
  geom_segment(aes(x = ActualStartTime, y = TaskName,
                   xend = ActualEndTime, yend = TaskName, color = status_color),
               size = 6) +
  scale_color_identity() +  # To use the pre-computed colors directly
  scale_x_datetime(date_breaks="01 hour", date_labels = "%H:%M") +
  ggtitle("Title") +
  xlab("") + ylab("") +
  
  theme_bw() + # Apply a classic theme with default font size
  theme(
    axis.text.x = element_text(angle = -30, vjust = 1, hjust = 0),
    axis.line = element_line(colour = "grey50",size =1 ),
    axis.text = element_text(color = "black", size = 10),
    plot.title = element_text(face = "bold", size = 12),
    panel.grid.major = element_line(color = "grey70", size = 0.4),
        panel.grid.minor = element_line(color = "grey70", size = 0.1))

  

# Print the plot
print(plot)

 


Sample Data 

TaskNameActualEndDateTimeActualStartDateTimeScheduledStartDateTimeScheduledEndDateTimeStatus
A27-04-2024 09:1627-04-2024 09:1626-04-2024 23:3027-04-2024 01:30Completed-Delayed
B26-04-2024 19:3626-04-2024 18:1626-04-2024 18:1526-04-2024 19:40Completed-On Time
C27-04-2024 05:1027-04-2024 04:3826-04-2024 22:4026-04-2024 23:30Completed-Delayed
D27-04-2024 04:3827-04-2024 02:5926-04-2024 20:0026-04-2024 22:10Completed-Delayed
E26-04-2024 18:5726-04-2024 18:4826-04-2024 18:4526-04-2024 19:15Completed-On Time
F27-04-2024 05:5727-04-2024 04:4126-04-2024 22:1526-04-2024 23:30Completed-Delayed


Any alternate visual suggestion which suits my requirement will be a great help. As this R visual is slow in peformance after publishing to service and shows an error as Script execution timeout  sometimes after published.

Note: Already tried Ghant chart but it will have only one start and one end time.

Thanks in Advance

3 REPLIES 3
ibarrau
Super User
Super User

Hi, I'm not sure about the double dates but the idea in general sounds like a Gantt graph. You could get custom visuals and try some Gantt chart. There are like 10 different ones.

I hope one of them might have want you need specifically here.


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Hi @ibarrau ,

I have tried gantt charts already and i couldnt find any gantt chart using four dates column, if you could help me finding the appropriate one it will be a great help.

Thanks!

Well if none of the many gantts available at the store let you build that visual, the only alternative would be the visuals that let you build inside, like html, deneb or d3js. Otherwise if you can't find anything that looks like the R visual, you might want to consider importing data or directlake (just in case you have or consider premium/fabric).

I hope that helps,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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