I have really been enjoying using and creating graphs in DiagrammeR
so far. I am able to create them in RStudio. Recently I was preparing a shiny app to include a graph using DiagrammeR
(grViz
function), I checked on the github and found examples of how to do the same (see here).
However I been trying but unable to get the output in a Shiny app.
Please find the below code which I am trying (app.R
) :
library(DiagrammeR)
library(shiny)
diagram <- "
digraph {
# graph attributes
graph [overlap = true]
# node attributes
node [shape = box,
fontname = Helvetica,
color = blue]
# edge attributes
edge [color = gray]
# node statements
A; B; C; D; E
F [color = black]
# node attributes
node [shape = circle,
fixedsize = true,
width = 0.9]
# node statements
1; 2; 3; 4; 5; 6; 7; 8
# edge statements
A->1; B->2 // gray
B->3 [color = red] // red
B->4 // gray
C->A [color = green] // green
1->D; E->A; 2->4; 1->5; 1->F // gray
E->6; 4->6; 5->7; 6->7 // gray
3->8 [color = blue] // blue
}
"
# Shiny app
server <- function(input, output) {
output$diagram <- renderGrViz({
grViz({
diagram
})
})
}
ui <- fluidPage(
grVizOutput('diagram', width = "100%", height = "760px")
)
shinyApp(ui = ui, server = server)
I am using R version 3.6.0, with shiny version 1.4.0, DiagrammeR version 1.0.5 on Windows 10 in Rstudio version 1.2.1335. On executing the above code I always get the following error and the Shiny app does not open.
> runApp()
Listening on http://127.0.0.1:4391
Warning: Error in htmlwidgets::shinyRenderWidget: unused argument (evn = env)
50: renderGrViz
49: server [C:\Users\HomeUser\Documents\RWorkSpace\SampleApp/app.R#46]
Error in htmlwidgets::shinyRenderWidget(expr = expr, outputFunction = grVizOutput, :
unused argument (evn = env)
Can anyone guide as to what is wrong with above code ?
I got the same error message as you, but when I downgraded the DiagrammeR package to 1.0.1 everything worked fine.
library(devtools)
install_version("DiagrammeR", version = "1.0.1", repos = "http://cran.us.r-project.org")