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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

anyone successfully generate sankey chart with R plotly in powerBI desktop and powerBI service?

hello,

I tried by best to create sankey chart with R plotly package in powerBI, but failed. I can create sankey in RStudio with same code.  I checked the official document that the package 'plotly' i used is supported by powerBI service. So there should be no reason the chart not displayed. https://docs.microsoft.com/en-us/power-bi/connect-data/service-r-packages-support

 

 

 

 

 

here is the r code:

library("plotly")

a = read.csv('cleanSankey.csv', header=TRUE, sep=',')
node_names <- unique(c(as.character(a$source), as.character(a$target)))
node_names <- node_names[order(sub('.*_', '', node_names))]
nodes <- data.frame(name = node_names)
links <- data.frame(source = match(a$source, node_names) - 1,
target = match(a$target, node_names) - 1,
value = a$value)

node_x <- c(0, 0, 0, 0,
0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
0.375, 0.375, 0.375, 0.375, 0.375, 0.375,
0.5, 0.5, 0.5, 0.5,
0.625, 0.6255, 0.625,
0.8, 0.8, 0.8,
0.999, 0.999)

node_y <- c(0.01, 0.02, 0.03, 0.04,
0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12,
0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08,
0.01, 0.02, 0.03, 0.04, 0.05, 0.06,
0.01, 0.02, 0.03, 0.04,
0.01, 0.02, 0.03,
0.01, 0.02, 0.03,
0.01, 0.02)

#Plot
plot_ly(type='sankey',
orientation = "h",
arrangement = "snap",
node = list (
label = node_names,
x = node_x,
y = node_y,
color = "grey",
pad = 15,
thinkness = 15,
line = list(color = "grey", width = 0.5)),

link = list(
source = links$source,
target = links$target,
value = links$value))

 

 

 

 

 

I run above code in powerBI desktop, but powerBI says that 'Can't display the visual'.

cheriemilk_0-1644918528899.png

 

Anyone has experience help to advice?

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

Hi @Anonymous ,

There's a article about this, hope it helps.

Interactive Charts using R and Power BI: Create Custom Visual Part 1 - RADACAD

Best Regards,
Community Support Team _ kalyj

 

 

View solution in original post

3 REPLIES 3
stevedep
Memorable Member
Memorable Member

You can take a look at this blog post. It describes how to add an interactive javascript Plotly Chart in Power BI. It's quite easy. 

 

Kind regards,

 

Steve.

Anonymous
Not applicable

@v-yanjiang-msft . i successfully plot the chart in powerBI by creating custom HTML R visual.

v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

There's a article about this, hope it helps.

Interactive Charts using R and Power BI: Create Custom Visual Part 1 - RADACAD

Best Regards,
Community Support Team _ kalyj

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors