Skip to contents

Extract the nodes from the tree that are selected in a more convenient format. You can choose which format you prefer.

Usage

get_selected(
  tree,
  format = c("names", "slices", "classid"),
  leaves_only = FALSE
)

Arguments

tree

The input$tree shinyTree you want to inspect.

format

In which format you want the output. Use names to get a simple list of the names (with attributes describing the node's ancestry), or slices to get a list of lists, each of which is a slice of the list used to get down to the selected node. classid gives each name with its stclass, stid and id (jsTree's id for the node) attributes instead of its ancestry.

leaves_only

If TRUE, return only selected nodes that have no children, leaving out selected parents. This works however deep each branch goes, unlike filtering slices by depth.

Value

A list with one element per selected node, descendants before their ancestors, in the form format gives. An empty list if nothing is selected or tree is NULL.

See also

Examples

tree <- list(
  World = structure(list(
    Europe = structure(list(
      Scandinavia = structure(list(
        Denmark = structure(0, stselected = TRUE),
        Sweden = structure(0, stselected = TRUE)
      ), stselected = TRUE),
      France = structure(0, stselected = TRUE)
    ), stselected = TRUE)
  ), stselected = TRUE)
)
unlist(get_selected(tree))
#> [1] "Denmark"     "Sweden"      "Scandinavia" "France"      "Europe"     
#> [6] "World"      
unlist(get_selected(tree, leaves_only = TRUE))
#> [1] "Denmark" "Sweden"  "France"