Type: | Package |
Title: | jsTree Bindings for Shiny |
Version: | 0.3.1 |
Date: | 2023-7-21 |
Maintainer: | Michael Bell <bell_michael_a@lilly.com> |
Description: | Exposes bindings to jsTree – a JavaScript library that supports interactive trees – to enable a rich, editable trees in Shiny. |
License: | MIT + file LICENSE |
Depends: | R (≥ 2.15.1), methods |
Imports: | shiny (≥ 0.9.0), htmlwidgets, jsonlite, stringr, promises |
Suggests: | testthat, shinytest, data.tree |
BugReports: | https://github.com/shinyTree/shinyTree/issues |
RoxygenNote: | 7.2.3 |
Encoding: | UTF-8 |
NeedsCompilation: | no |
Packaged: | 2023-08-07 16:36:45 UTC; c038195 |
Author: | 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] |
Repository: | CRAN |
Date/Publication: | 2023-08-07 18:30:02 UTC |
Check depth of a list
Description
Check depth of a list
Usage
depth(x)
Arguments
x |
list |
Value
integer
Author(s)
Jasper Schelfhout jasper.schelfhout@openanalytics.eu
Converts a data.frame to a data.tree format
Description
Converts a data.frame to a data.tree format
Usage
dfToTree(df, hierarchy = colnames(df))
Arguments
df |
data.frame |
hierarchy |
ordered character vector of column names defining the hierarchy |
Value
nested list
Author(s)
Jasper Schelfhout jasper.schelfhout@openanalytics.eu
Examples
## Not run:
df <- data.frame(Titanic)
tree <- dfToTree(df, c("Sex", "Class", "Survived"))
## End(Not run)
Recursively apply function to all data.frames in a nested list
Description
Recursively apply function to all data.frames in a nested list
Usage
dfrapply(list, f, ...)
Arguments
list |
(nested) list containing data.frames |
f |
function to apply to each data.frame |
... |
extra arguments to f |
Value
list
Author(s)
Jasper Schelfhout jasper.schelfhout@openanalytics.eu
Get the checked nodes from a tree
Description
Extract the nodes from the tree that are checked in a more convenient format. You can choose which format you prefer.
Usage
get_checked(tree, format = c("names", "slices", "classid"))
Arguments
tree |
The |
format |
In which format you want the output. Use
|
Get the selected nodes from a tree
Description
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"))
Arguments
tree |
The |
format |
In which format you want the output. Use
|
Render an empty ShinyTree
Description
Renders a tree with no defined nodes.
Usage
renderEmptyTree()
See Also
Render a ShinyTree
Description
Should return a list from the given expression which will be converted into a
shinyTree
.
Usage
renderTree(expr, env = parent.frame(), quoted = FALSE)
Arguments
expr |
The expression to be evaluated which should produce a list. |
env |
The environment in which |
quoted |
Is |
See Also
Render an asynchronous ShinyTree
Description
Should return a list from the given expression which will be converted into a
shinyTree
.
Usage
renderTreeAsync(expr, env = parent.frame(), quoted = FALSE)
Arguments
expr |
The expression to be evaluated which should produce a list. |
env |
The environment in which |
quoted |
Is |
See Also
Tree traversal
Description
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.
Usage
set_node_attrs(tree, attr_name, inner_val, leaf_val)
Arguments
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 |
Value
named nested list
Examples
tree <- dfToTree(data.frame(Titanic), c("Sex", "Survived"))
str(set_node_attrs(tree, attr_name = "sttype", inner_val = "directory", leaf_val = "file"))
Create a Shiny Tree
Description
This creates a spot in your Shiny UI for a shinyTree which can then be filled
in using renderTree
.
Usage
shinyTree(
outputId,
checkbox = FALSE,
search = FALSE,
searchtime = 250,
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
)
Arguments
outputId |
The ID associated with this element |
checkbox |
If |
search |
If |
searchtime |
Determines the reaction time of the search algorithm. Default is 250ms. |
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 |
Details
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.
See Also
Convert tree into data.frame
Description
Convert tree into data.frame
Usage
treeToDf(tree, hierarchy = NULL)
Arguments
tree |
named nested list |
hierarchy |
sorted character vector with name for each level of the list |
Value
data.frame
Author(s)
Michael Bell
Examples
## Not run:
df <- data.frame(Titanic)
tree <- dfToTree(df, c("Sex", "Class", "Survived"))
newDf <- treeToDf(tree, c("Sex", "Class", "Survived"))
## End(Not run)
Converts a data.tree to a JSON format
Description
Walk through a data.tree
and constructs a JSON string,
which can be rendered by shinyTree.
Usage
treeToJSON(
tree,
keepRoot = FALSE,
topLevelSlots = c("default", "all"),
createNewId = TRUE,
pretty = FALSE
)
Arguments
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 |
Details
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.
Value
a JSON string representing the data.tree
Note
updateTree
and renderTree
need an unevaluated JSON
string. Hence, this function returns a string rather than the JSON object itself.
Author(s)
Thorn Thaler, thorn.thaler@thothal.at
Update the tree with new data
Description
Extract the nodes from the tree that are selected in a more convenient format. You can choose which format you prefer.
Usage
updateTree(session, treeId, data = NULL)
Arguments
session |
The current session variable. |
treeId |
The identifier for the shinyTree object |
data |
JSON data or nested list representing the new tree structure. |