| Title: | jsTree Bindings for Shiny |
|---|---|
| Description: | Exposes bindings to jsTree -- a JavaScript library that supports interactive trees -- to enable a rich, editable trees in Shiny. |
| Authors: | Trestle Technology, LLC [aut], Jeff Allen [aut], Institut de Radioprotection et de Sûreté Nucléaire [cph], Ivan Bozhanov [ctb, cph] (jsTree), The Dojo Foundation [ctb, cph] (require.js), jQuery Foundation, Inc. [ctb, cph], Mike Schaffer [ctb], Timm Danker [ctb], Michael Bell [cre], Sebastian Gatscha [ctb], Thorn Thaler [ctb] |
| Maintainer: | Michael Bell <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.1 |
| Built: | 2026-06-01 08:03:58 UTC |
| Source: | https://github.com/shinytree/shinytree |
Check depth of a list
depth(x)depth(x)
x |
list |
integer
Jasper Schelfhout [email protected]
Recursively apply function to all data.frames in a nested list
dfrapply(list, f, ...)dfrapply(list, f, ...)
list |
(nested) list containing data.frames |
f |
function to apply to each data.frame |
... |
extra arguments to f |
list
Jasper Schelfhout [email protected]
Converts a data.frame to a data.tree format
dfToTree(df, hierarchy = colnames(df))dfToTree(df, hierarchy = colnames(df))
df |
data.frame |
hierarchy |
ordered character vector of column names defining the hierarchy |
nested list
Jasper Schelfhout [email protected]
## Not run: df <- data.frame(Titanic) tree <- dfToTree(df, c("Sex", "Class", "Survived")) ## End(Not run)## Not run: df <- data.frame(Titanic) tree <- dfToTree(df, c("Sex", "Class", "Survived")) ## End(Not run)
Extract the nodes from the tree that are checked in a more convenient format. You can choose which format you prefer.
get_checked(tree, format = c("names", "slices", "classid"))get_checked(tree, format = c("names", "slices", "classid"))
tree |
The |
format |
In which format you want the output. Use
|
Extract the nodes from the tree that are selected in a more convenient format. You can choose which format you prefer.
get_selected(tree, format = c("names", "slices", "classid"))get_selected(tree, format = c("names", "slices", "classid"))
tree |
The |
format |
In which format you want the output. Use
|
Renders a tree with no defined nodes.
renderEmptyTree()renderEmptyTree()
Should return a list from the given expression which will be converted into a
shinyTree.
renderTree(expr, env = parent.frame(), quoted = FALSE)renderTree(expr, env = parent.frame(), quoted = FALSE)
expr |
The expression to be evaluated which should produce a list. |
env |
The environment in which |
quoted |
Is |
Should return a list from the given expression which will be converted into a
shinyTree.
renderTreeAsync(expr, env = parent.frame(), quoted = FALSE)renderTreeAsync(expr, env = parent.frame(), quoted = FALSE)
expr |
The expression to be evaluated which should produce a list. |
env |
The environment in which |
quoted |
Is |
Traverse through tree/list to set node attributes, e.g. change icons. Useful for directory structure icons where inner nodes are directories, leafs are files.
set_node_attrs(tree, attr_name, inner_val, leaf_val)set_node_attrs(tree, attr_name, inner_val, leaf_val)
tree |
named nested list |
attr_name |
name of attribute to set |
inner_val |
value of attribute for inner tree nodes |
leaf_val |
value of attribute for outer tree nodes |
named nested list
tree <- dfToTree(data.frame(Titanic), c("Sex", "Survived")) str(set_node_attrs(tree, attr_name = "sttype", inner_val = "directory", leaf_val = "file"))tree <- dfToTree(data.frame(Titanic), c("Sex", "Survived")) str(set_node_attrs(tree, attr_name = "sttype", inner_val = "directory", leaf_val = "file"))
This creates a spot in your Shiny UI for a shinyTree which can then be filled
in using renderTree.
shinyTree( outputId, checkbox = FALSE, search = FALSE, searchtime = 250, searchplaceholder = "", dragAndDrop = FALSE, types = NULL, theme = "default", themeIcons = TRUE, themeDots = TRUE, sort = FALSE, unique = FALSE, wholerow = FALSE, stripes = FALSE, multiple = TRUE, animation = 200, contextmenu = FALSE, three_state = TRUE, whole_node = TRUE, tie_selection = TRUE )shinyTree( outputId, checkbox = FALSE, search = FALSE, searchtime = 250, searchplaceholder = "", dragAndDrop = FALSE, types = NULL, theme = "default", themeIcons = TRUE, themeDots = TRUE, sort = FALSE, unique = FALSE, wholerow = FALSE, stripes = FALSE, multiple = TRUE, animation = 200, contextmenu = FALSE, three_state = TRUE, whole_node = TRUE, tie_selection = TRUE )
outputId |
The ID associated with this element |
checkbox |
If |
search |
If |
searchtime |
Determines the reaction time of the search algorithm. Default is 250ms. |
searchplaceholder |
Add a placeholder value to the search box |
dragAndDrop |
If |
types |
enables jstree types functionality when sent proper json (please see the types example) |
theme |
jsTree theme, one of |
themeIcons |
If |
themeDots |
If |
sort |
If |
unique |
If |
wholerow |
If |
stripes |
If |
multiple |
If |
animation |
The open / close animation duration in milliseconds.
Set this to |
contextmenu |
If |
three_state |
If |
whole_node |
If |
tie_selection |
If |
A shinyTree is an output *and* an input element in the same time. While you can
fill it via renderTree you can access its content via input$tree
(for example after the user rearranged some nodes). By default, input$tree will
return a list similiar to the one you use to fill the tree. This behaviour is controlled
by getOption("shinyTree.defaultParser"). It defaults to "list", but can be set
to "tree", in which case a data.tree is returned.
Convert tree into data.frame
treeToDf(tree, hierarchy = NULL)treeToDf(tree, hierarchy = NULL)
tree |
named nested list |
hierarchy |
sorted character vector with name for each level of the list |
data.frame
Michael Bell
## Not run: df <- data.frame(Titanic) tree <- dfToTree(df, c("Sex", "Class", "Survived")) newDf <- treeToDf(tree, c("Sex", "Class", "Survived")) ## End(Not run)## Not run: df <- data.frame(Titanic) tree <- dfToTree(df, c("Sex", "Class", "Survived")) newDf <- treeToDf(tree, c("Sex", "Class", "Survived")) ## End(Not run)
Walk through a data.tree and constructs a JSON string,
which can be rendered by shinyTree.
treeToJSON( tree, keepRoot = FALSE, topLevelSlots = c("default", "all"), createNewId = TRUE, pretty = FALSE )treeToJSON( tree, keepRoot = FALSE, topLevelSlots = c("default", "all"), createNewId = TRUE, pretty = FALSE )
tree |
the data.tree which should be parses |
keepRoot |
logical. If |
topLevelSlots |
determines which slots should be moved to the top level of the
node. If |
createNewId |
logical. If |
pretty |
logical. If |
The JSON string generated follows the jsTree specifications. In particular it encodes children nodes via the ‘children’ slot.
All atomic or list slots of a node in the tree are stored in a data slot in the resulting JSON.
If the user wants to store some slots not in the data slot but on the top
level of the node, parameter topLevelSlots can be used. This is useful
for additional parameters such as ‘icon’, ‘li_attr’ or
‘a_attr’, which jsTree expect to be on the top level of the node.
An example of how to make use of this functionality can be found in the example folder of this library.
a JSON string representing the data.tree
updateTree and renderTree need an unevaluated JSON
string. Hence, this function returns a string rather than the JSON object itself.
Thorn Thaler, [email protected]
Extract the nodes from the tree that are selected in a more convenient format. You can choose which format you prefer.
updateTree(session, treeId, data = NULL)updateTree(session, treeId, data = NULL)
session |
The current session variable. |
treeId |
The identifier for the shinyTree object |
data |
JSON data or nested list representing the new tree structure. |