1

I'm working on a shiny app which plots data trees. I'm looking to incorporate the shinyTree app to permit quick comparison of plotted nodes. The issue is that the shinyTree app returns a redundant list of lists of the sub node plot.

enter image description here

The actual list of list is included below. I would like to keep the longest branches only. I would also like to remove the id node (integer node), I'm struggling as to why it even shows up based on the list. I have tried many different methods to work with this list but it's been a real struggle. The list concept is difficult to understand.

I create the data.tree and plot via:

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
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
int64
  • 81
  • 4
  • Could you include your list with `dput()`? Then everyone can import the data and try to help you. – SeGa Oct 20 '18 at 22:12

1 Answers1

1

Well, I did cobble together a poor hack to make this work here is what I did to the 'checkList' list

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

The new checkList looks like this:

[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"                                     

It works :)... but I think this could be done with a two liner.... I'll work on it again in a week or so. Any other Ideas would be appreciated.

int64
  • 81
  • 4