到目前为止,我真的很喜欢在DiagrammeR中使用和创建图形。我可以在RStudio中创建它们。最近,我正在准备一个闪亮的应用程序,以包含使用DiagrammeRgrViz函数)的图形,我在github上进行了检查,并找到了执行该操作的示例(请参见here)。
但是我一直在尝试,但是无法在Shiny应用程序中获得输出。
请找到我正在尝试的以下代码(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)


我在Rstudio版本1.2.1335的Windows 10上使用R版本3.6.0,闪亮版本1.4.0,DiagrammeR版本1.0.5。在执行上述代码时,我始终会收到以下错误,并且Shiny应用程序无法打开。

> 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)


任何人都可以指导上述代码有什么问题吗?

最佳答案

我收到了与您相同的错误消息,但是当我将DiagrammeR软件包降级到1.0.1时,一切正常。

library(devtools)
install_version("DiagrammeR", version = "1.0.1", repos = "http://cran.us.r-project.org")

07-24 09:52