使用R数据



我试图添加一些代码到一个现有的闪亮的应用程序,将显示一个数据的图形版本。树状结构。下面的代码成功地创建了数据。树的方式,我希望它显示在我闪亮的应用程序的窗口内。然而,我找不到任何方法来渲染'theTree',使其出现在RStudio查看器中。

library(data.tree)
treedata <- data.frame(c("Product A", "Product A", "Product A", "Product A", "Product A", "Product A"),
c("Sub-A", "Sub-A", "Sub-A", "Sub-B", "Sub-B", "Sub-B"),
c("Comp-1", "Comp-1", "*", "Comp-2", "Comp-2", "*"),
c("SubCompA", "SubCompB", "SubCompC", "SubCompA", "SubCompB", "SubCompC"))
names(treedata) <- c("ProductName", "SubProjects", "Component" ,"SQComponents")
product <- "Product A"
treedata$pathString <- paste(product,
treedata$SubProjects,
treedata$Component,
treedata$SQComponents,
sep = "/")
theTree <- as.Node(treedata)
SetGraphStyle(theTree, rankdir = "TB")
SetEdgeStyle(theTree, arrowhead = "vee", color = "grey35", penwidth = 2)
SetNodeStyle(theTree, style = "filled,rounded", shape = "box", fillcolor = "GreenYellow",
fontname = "helvetica",
fontcolor = "black",
tooltip = GetDefaultTooltip)
p <- plot(theTree)
print(p)

这是一个'grViz' HTML小部件。下面是如何在Shiny中渲染它:

library(shiny)
library(DiagrammeR)
library(data.tree)
treedata <- data.frame(
c("Product A", "Product A", "Product A", "Product A", "Product A", "Product A"),
c("Sub-A", "Sub-A", "Sub-A", "Sub-B", "Sub-B", "Sub-B"),
c("Comp-1", "Comp-1", "*", "Comp-2", "Comp-2", "*"),
c("SubCompA", "SubCompB", "SubCompC", "SubCompA", "SubCompB", "SubCompC")
)
names(treedata) <- 
c("ProductName", "SubProjects", "Component" ,"SQComponents")
product <- "Product A"
treedata$pathString <- paste(product,
treedata$SubProjects,
treedata$Component,
treedata$SQComponents,
sep = "/")
theTree <- as.Node(treedata)
SetGraphStyle(theTree, rankdir = "TB")
SetEdgeStyle(theTree, arrowhead = "vee", color = "grey35", penwidth = 2)
SetNodeStyle(theTree, style = "filled,rounded", shape = "box", 
fillcolor = "GreenYellow",
fontname = "helvetica",
fontcolor = "black",
tooltip = GetDefaultTooltip)
p <- plot(theTree)
ui <- fluidPage(
grVizOutput("tree")
)
server <- function(input, output, session){
output[["tree"]] <- renderGrViz(p)
}
shinyApp(ui, server)

相关内容

  • 没有找到相关文章

最新更新