1

我正在开发一个绘制数据树的闪亮应用程序。我正在寻找合并 shinyTree 应用程序以允许快速比较绘制的节点。问题是 shinyTree 应用程序返回子节点图列表的冗余列表。

在此处输入图像描述

列表的实际列表包括在下面。我只想保留最长的树枝。我还想删除 id 节点(整数节点),我正在努力为什么它甚至会根据列表显示。我尝试了许多不同的方法来处理这个列表,但这是一场真正的斗争。列表的概念很难理解。

我通过以下方式创建 data.tree 和绘图:

dataTree.a <- FromListSimple(checkList)
plot(dataTree.a)
> checkList
[[1]]
[[1]]$Asia
[[1]]$Asia$China
[[1]]$Asia$China$Beijing
[[1]]$Asia$China$Beijing$Round
[[1]]$Asia$China$Beijing$Round$`20383994`
[1] 0


[[2]]
[[2]]$Asia
[[2]]$Asia$China
[[2]]$Asia$China$Beijing
[[2]]$Asia$China$Beijing$Round
[1] 0


[[3]]
[[3]]$Asia
[[3]]$Asia$China
[[3]]$Asia$China$Beijing
[1] 0


[[4]]
[[4]]$Asia
[[4]]$Asia$China
[[4]]$Asia$China$Shanghai
[[4]]$Asia$China$Shanghai$Round
[[4]]$Asia$China$Shanghai$Round$`23740778`
[1] 0


[[5]]
[[5]]$Asia
[[5]]$Asia$China
[[5]]$Asia$China$Shanghai
[[5]]$Asia$China$Shanghai$Round
[1] 0


[[6]]
[[6]]$Asia
[[6]]$Asia$China
[[6]]$Asia$China$Shanghai
[1] 0


[[7]]
[[7]]$Asia
[[7]]$Asia$China
[1] 0


[[8]]
[[8]]$Asia
[[8]]$Asia$India
[[8]]$Asia$India$Delhi
[[8]]$Asia$India$Delhi$Round
[[8]]$Asia$India$Delhi$Round$`25703168`
[1] 0


[[9]]
[[9]]$Asia
[[9]]$Asia$India
[[9]]$Asia$India$Delhi
[[9]]$Asia$India$Delhi$Round
[1] 0


[[10]]
[[10]]$Asia
[[10]]$Asia$India
[[10]]$Asia$India$Delhi
[1] 0


[[11]]
[[11]]$Asia
[[11]]$Asia$India
[1] 0


[[12]]
[[12]]$Asia
[[12]]$Asia$Japan
[[12]]$Asia$Japan$Tokyo
[[12]]$Asia$Japan$Tokyo$Round
[[12]]$Asia$Japan$Tokyo$Round$`38001000`
[1] 0


[[13]]
[[13]]$Asia
[[13]]$Asia$Japan
[[13]]$Asia$Japan$Tokyo
[[13]]$Asia$Japan$Tokyo$Round
[1] 0


[[14]]
[[14]]$Asia
[[14]]$Asia$Japan
[[14]]$Asia$Japan$Tokyo
[1] 0


[[15]]
[[15]]$Asia
[[15]]$Asia$Japan
[1] 0


[[16]]
[[16]]$Asia
[1] 0
4

1 回答 1

0

好吧,我确实拼凑了一个糟糕的黑客来完成这项工作,这就是我对“检查清单”列表所做的

checkList <- get_selected(tree, format = "slices")

  # Convert and collapse shinyTree slices to data.tree
  #   This is a bit of a cluge to work the graphic with
  # shinyTree an alternate one liner is in works
  #   This transform works by finding the longest branches
  # and only plotting them since the other branches are
  # subsets due to the slices.

  # Extract the checkList name (as characters) from the checkList
  tmp <- names(unlist(checkList)) 

  # Determine the length of the individual checkList Names
  lens <- lapply(tmp, function(x) length(strsplit(x, ".", fixed=TRUE)[[1]]))

  # Find the elements with the highest length returns a list of high vals
  lens.max <- which(lens == max(sapply(lens, max)))

  # Replace all '.' with '\' prepping for DataFrameTable Converions
  tmp <- relist(str_replace_all(tmp, "\\.", "/"), skeleton=tmp)

  # Add a root node to work with multiple branches
  tmp <- unlist(lapply(tmp, function(x) paste0("Root/", x)))

  # Create a list of only the longest branches
  longBranches <- as.list(tmp[lens.max])

  # Convert the list into a data.frame for convert
  longBranches.df <- data.frame(pathString = do.call(rbind, longBranches))

  # Publish the data.frame for use 
  vals$selDF <- longBranches.df

  #save(checkList, file = "chkLists.RData") # Save for troubleshooting

  print(vals$selDF)ode here

新的 checkList 如下所示:

[1] "Root/Europe/France/Paris/Round/10843285"          "Root/Europe/France/Paris/Round"                  
 [3] "Root/Europe/France/Paris"                         "Root/Europe/France"                              
 [5] "Root/Europe/Germany/Berlin/Diamond/3563194"       "Root/Europe/Germany/Berlin/Diamond"              
 [7] "Root/Europe/Germany/Berlin/Round/3563194"         "Root/Europe/Germany/Berlin/Round"                
 [9] "Root/Europe/Germany/Berlin"                       "Root/Europe/Germany"                             
[11] "Root/Europe/Italy/Rome/Round/3717956"             "Root/Europe/Italy/Rome/Round"                    
[13] "Root/Europe/Italy/Rome"                           "Root/Europe/Italy"                               
[15] "Root/Europe/United Kingdom/London/Round/10313307" "Root/Europe/United Kingdom/London/Round"         
[17] "Root/Europe/United Kingdom/London"                "Root/Europe/United Kingdom"                      
[19] "Root/Europe"                                     

它可以工作:)...但我认为这可以用两个班轮来完成....我会在一周左右的时间里再做一次。任何其他想法将不胜感激。

于 2018-06-21T20:34:37.993 回答