DiagrammeR
DiagrammeR copied to clipboard
DiagrammeROutput and renderDiagrammeR just produce text output with render_graph
I've been trying to use DiagrammeR
to put some graphs into a shiny app. While the Graphviz renderers work, just using native DiagrammeR syntax merely produces raw digraph output. So, the following code:
library(shiny)
library(DiagrammeR)
ui <- pageWithSidebar(
headerPanel("Test"),
sidebarPanel(
),
mainPanel(
DiagrammeROutput("plotMatrix")
)
)
server <- function(input,output){
output$plotMatrix <- renderDiagrammeR({
create_graph() %>%
add_balanced_tree(
k = 2, h = 3) %>%
render_graph()
})
}
shinyApp(ui, server)
renders no graph, but instead the text
digraph {
graph [layout = "neato",
outputorder = "edgesfirst",
bgcolor = "white"]
node [fontname = "Helvetica",
fontsize = "10",
shape = "circle",
fixedsize = "true",
width = "0.5",
style = "filled",
fillcolor = "aliceblue",
color = "gray70",
fontcolor = "gray50"]
edge [fontname = "Helvetica",
fontsize = "8",
len = "1.5",
color = "gray80",
arrowsize = "0.5"]
"1" [label = "1", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"2" [label = "2", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"3" [label = "3", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"4" [label = "4", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"5" [label = "5", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"6" [label = "6", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"7" [label = "7", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"8" [label = "8", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"9" [label = "9", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"10" [label = "10", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"11" [label = "11", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"12" [label = "12", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"13" [label = "13", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"14" [label = "14", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"15" [label = "15", fillcolor = "#F0F8FF", fontcolor = "#000000"]
"1"->"2"
The renderDiagrammeR()
function requires a fix for this (to recognize that a dgr_graph
is being used as the expr
). However, could you try using the generate_dot()
function in place of render_graph()
?
I ran into the same issue, using generate_dot does not solve it, I get the following error instead: $ operator is invalid for atomic vectors
UPDATE What does work is just change DiagrammeROutput with grVizOutput and renderDiagrammeR with renderGrViz