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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Custom Rscript - problem with published DiagrammeR. attr_theme doesn't refer to any available theme

Hello,

 

I have quite a bizzare error. On PowerBI desktop everything works flawlessly. But when I publish report online I receive an error  on Rsctipt Visual. attr_theme does not refer to anything while clearly it refers to working attribute.

 image_2022-01-04_182413.png

 

Code looks like this: 

 

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script: 

# dataset <- data.frame(Ship From, Ship To, volume)
# dataset <- unique(dataset)

# Paste or type your script code here:


library(DiagrammeR)
uniquenodes <- unique(c(dataset$'Ship From', dataset$'Ship To'))
uniquenodes
options(scipen=99)


nodes <- create_node_df(n=length(uniquenodes),
                        label=uniquenodes,
                        color="DodgerBlue",
                        fillcolor ="GhostWhite",
                        shape ="rectangle",
                        fontcolor ="RoyalBlue4",
                        penwidth =2,
                        fontsize =16,
                        height =0.5,
                        width =0.7,
                        mindist =5)

edges <- create_edge_df(from =match(dataset$'Ship From', uniquenodes), 
                        to =match(dataset$'Ship To', uniquenodes), 
                        rel ="leads_to",
                        label =dataset$volume,
                        fontsize =14,
                        color ="SlateGray",
                        penwidth =2,
                        arrowsize =1)

g <- create_graph(nodes_df=nodes, 
                  edges_df =edges,
                  directed =TRUE,
                  attr_theme ="lr")
                  
tmp <- export_graph(g, file_name ="image.png", file_type ="png")

 

the custom Rscript visual renders in Desktop version as follows: 

Han_Solo_0-1641317213778.png

my question is. How is it possible that Rscript renders on desktop correctly and not on published web version?

Best Regards 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello,

 

@v-yanjiang-msft I was able to fix this. Apparently Power BI handles characters differently than R. 

First I assigned layout attribute not in create_graph function but in add_global_graph_attrs as "layout" and "rankdir" which eliminated the issue.

 

dataset$'Ship From' <- as.character(dataset$'Ship From')
dataset$'Ship To' <- as.character(dataset$'Ship To')

 

Then I changed uniquenodes values from integers to characters to able Power BI to match the values. with piping. 

 

g <- create_graph(nodes_df = nodes,
                  edges_df = edges,
                  directed = TRUE) %>% add_global_graph_attrs(
                    attr = c("layout", "rankdir"),
                    value = c("dot", "LR"),
                    attr_type = c("graph", "graph")
                  )

 

the whole code looks like this:

 

 

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:

# dataset <- data.frame(Ship From, Ship To, volume)
# dataset <- unique(dataset)

# Paste or type your script code here:

library(DiagrammeR)
options(scipen = 99)
dataset$'Ship From' <- as.character(dataset$'Ship From')
dataset$'Ship To' <- as.character(dataset$'Ship To')
uniquenodes <- unique(c(dataset$'Ship From', dataset$'Ship To'))

nodes <- create_node_df(
  n = length(uniquenodes),
  label = uniquenodes,
  type = uniquenodes,
  color = "DodgerBlue",
  fillcolor = "GhostWhite",
  shape = "rectangle",
  fontcolor = "RoyalBlue4",
  penwidth = 2,
  fontsize = 16,
  height = 0.5,
  width = 0.7,
  mindist = 5
)

edges <-
  create_edge_df(
    from = factor(dataset$'Ship From', levels = uniquenodes),
    to = factor(dataset$'Ship To', levels = uniquenodes),
    rel = "leading_to",
    label = dataset$volume,
    fontsize = 14,
    color = "SlateGray",
    penwidth = 2,
    arrowsize = 1
  )

g <- create_graph(nodes_df = nodes,
                  edges_df = edges,
                  directed = TRUE) %>% add_global_graph_attrs(
                    attr = c("layout", "rankdir"),
                    value = c("dot", "LR"),
                    attr_type = c("graph", "graph")
                  )

tmp <- export_graph(g, file_name = "image.png", file_type = "png")

 

 



View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hello,

 

I was able to fix this. Apparently Power BI handles characters differently than R. 

First I assigned layout attribute not in create_graph function but in add_global_graph_attrs as "layout" and "rankdir" which eliminated the issue.

 

dataset$'Ship From' <- as.character(dataset$'Ship From')
dataset$'Ship To' <- as.character(dataset$'Ship To')

 

Then I changed uniquenodes values from integers to characters to able Power BI to match the values. with piping. 

 

g <- create_graph(nodes_df = nodes,
                  edges_df = edges,
                  directed = TRUE) %>% add_global_graph_attrs(
                    attr = c("layout", "rankdir"),
                    value = c("dot", "LR"),
                    attr_type = c("graph", "graph")
                  )

 

the whole code looks like this:

 

 

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:

# dataset <- data.frame(Ship From, Ship To, volume)
# dataset <- unique(dataset)

# Paste or type your script code here:

library(DiagrammeR)
options(scipen = 99)
dataset$'Ship From' <- as.character(dataset$'Ship From')
dataset$'Ship To' <- as.character(dataset$'Ship To')
uniquenodes <- unique(c(dataset$'Ship From', dataset$'Ship To'))

nodes <- create_node_df(
  n = length(uniquenodes),
  label = uniquenodes,
  type = uniquenodes,
  color = "DodgerBlue",
  fillcolor = "GhostWhite",
  shape = "rectangle",
  fontcolor = "RoyalBlue4",
  penwidth = 2,
  fontsize = 16,
  height = 0.5,
  width = 0.7,
  mindist = 5
)

edges <-
  create_edge_df(
    from = factor(dataset$'Ship From', levels = uniquenodes),
    to = factor(dataset$'Ship To', levels = uniquenodes),
    rel = "leading_to",
    label = dataset$volume,
    fontsize = 14,
    color = "SlateGray",
    penwidth = 2,
    arrowsize = 1
  )

g <- create_graph(nodes_df = nodes,
                  edges_df = edges,
                  directed = TRUE) %>% add_global_graph_attrs(
                    attr = c("layout", "rankdir"),
                    value = c("dot", "LR"),
                    attr_type = c("graph", "graph")
                  )

tmp <- export_graph(g, file_name = "image.png", file_type = "png")

 

 



v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

There are some limitations when you use R script on power bi service, you can take the following links for reference:

Creating R visuals in the Power BI service

R packages in the Power BI service

As the document states that custom R packages are not supported in Power BI Service.


Known Limitations

R visuals in the Power BI service have a few limitations:


Best Regards,
Community Support Team _ kalyj

 

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

Anonymous
Not applicable

Hello,

 

@v-yanjiang-msft I was able to fix this. Apparently Power BI handles characters differently than R. 

First I assigned layout attribute not in create_graph function but in add_global_graph_attrs as "layout" and "rankdir" which eliminated the issue.

 

dataset$'Ship From' <- as.character(dataset$'Ship From')
dataset$'Ship To' <- as.character(dataset$'Ship To')

 

Then I changed uniquenodes values from integers to characters to able Power BI to match the values. with piping. 

 

g <- create_graph(nodes_df = nodes,
                  edges_df = edges,
                  directed = TRUE) %>% add_global_graph_attrs(
                    attr = c("layout", "rankdir"),
                    value = c("dot", "LR"),
                    attr_type = c("graph", "graph")
                  )

 

the whole code looks like this:

 

 

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:

# dataset <- data.frame(Ship From, Ship To, volume)
# dataset <- unique(dataset)

# Paste or type your script code here:

library(DiagrammeR)
options(scipen = 99)
dataset$'Ship From' <- as.character(dataset$'Ship From')
dataset$'Ship To' <- as.character(dataset$'Ship To')
uniquenodes <- unique(c(dataset$'Ship From', dataset$'Ship To'))

nodes <- create_node_df(
  n = length(uniquenodes),
  label = uniquenodes,
  type = uniquenodes,
  color = "DodgerBlue",
  fillcolor = "GhostWhite",
  shape = "rectangle",
  fontcolor = "RoyalBlue4",
  penwidth = 2,
  fontsize = 16,
  height = 0.5,
  width = 0.7,
  mindist = 5
)

edges <-
  create_edge_df(
    from = factor(dataset$'Ship From', levels = uniquenodes),
    to = factor(dataset$'Ship To', levels = uniquenodes),
    rel = "leading_to",
    label = dataset$volume,
    fontsize = 14,
    color = "SlateGray",
    penwidth = 2,
    arrowsize = 1
  )

g <- create_graph(nodes_df = nodes,
                  edges_df = edges,
                  directed = TRUE) %>% add_global_graph_attrs(
                    attr = c("layout", "rankdir"),
                    value = c("dot", "LR"),
                    attr_type = c("graph", "graph")
                  )

tmp <- export_graph(g, file_name = "image.png", file_type = "png")

 

 



Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.