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$treeshinyTree you want to inspect.- format
In which format you want the output. Use
namesto get a simple list of the names (with attributes describing the node's ancestry), orslicesto get a list of lists, each of which is a slice of the list used to get down to the selected node.classidgives each name with itsstclass,stidandid(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 filteringslicesby 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.
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"