Title: | Create Interactive Collapsible Trees with the JavaScript 'D3' Library |
---|---|
Description: | Create and customize interactive collapsible 'D3' trees using the 'D3' JavaScript library and the 'htmlwidgets' package. These trees can be used directly from the R console, from 'RStudio', in Shiny apps and R Markdown documents. When in Shiny the tree layout is observed by the server and can be used as a reactive filter of structured data. |
Authors: | Jonathan Sidi [aut, cre], Kenton Russell [ctb] (https://github.com/timelyportfolio) |
Maintainer: | Jonathan Sidi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.0 |
Built: | 2024-10-25 03:46:26 UTC |
Source: | https://github.com/yonicd/d3tree |
Htmlwidget that binds to d3js trees. When used in Shiny environment the widget returns a data.frame of logical expressions that represent the current state of the tree.
d3tree( data, name = "name", value = "value", direction = "horizontal", activeReturn = NULL, width = NULL, height = NULL, elementId = NULL )
d3tree( data, name = "name", value = "value", direction = "horizontal", activeReturn = NULL, width = NULL, height = NULL, elementId = NULL )
data |
named list containing hierarchy structure of data created by df2tree and the layout of the tree (collapse,radial,cartesian) |
name |
character containing the names of the nodes |
value |
character containing the name of the tooltip column that are used in the leafs |
direction |
charater containing the direction the collapsible tree layout will grow to horizontal or vertical (can be 'h','v') |
activeReturn |
character vector of node attributes to observe and return to shiny. |
width , height
|
Must be a valid CSS unit (like |
elementId |
The input slot that will be used to access the element. |
activeReturn is set to NULL by default, but can return any attributes that are strings or numeric such as: name,value,depth,id.
Any node attributes requested that are not found in the node keys are ignored.
if(interactive()){ d3tree(list(root = df2tree( rootname='Titanic', struct=as.data.frame(Titanic) ), layout = 'collapse') ) d3tree(list( root = df2tree( rootname = 'Titanic', struct = as.data.frame(Titanic), tool_tip = letters[1:(ncol(as.data.frame(Titanic))+1)] ), layout = 'collapse') ) d3tree(list( root = df2tree( rootname = 'book', struct = stan.models), layout = 'collapse') ) }
if(interactive()){ d3tree(list(root = df2tree( rootname='Titanic', struct=as.data.frame(Titanic) ), layout = 'collapse') ) d3tree(list( root = df2tree( rootname = 'Titanic', struct = as.data.frame(Titanic), tool_tip = letters[1:(ncol(as.data.frame(Titanic))+1)] ), layout = 'collapse') ) d3tree(list( root = df2tree( rootname = 'book', struct = stan.models), layout = 'collapse') ) }
Output and render functions for using d3tree within Shiny applications and interactive Rmd documents.
d3treeOutput(outputId, width = "100%", height = "400px") renderD3tree(expr, env = parent.frame(), quoted = FALSE)
d3treeOutput(outputId, width = "100%", height = "400px") renderD3tree(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a d3tree |
env |
The environment in which to evaluate |
quoted |
Is |
converts dataframe to json to send to javascript
df2tree(struct, rootname = "root", tool_tip = NULL)
df2tree(struct, rootname = "root", tool_tip = NULL)
struct |
data.frame containing the structure the tree will represent |
rootname |
character name of the root node |
tool_tip |
charater vector of the label to give to the nodes in each hierarchy |
titanic_df <- as.data.frame(Titanic) df2tree(struct = titanic_df,rootname = 'Titanic') df2tree( struct = titanic_df, rootname = 'Titanic', tool_tip = letters[1:5] )
titanic_df <- as.data.frame(Titanic) df2tree(struct = titanic_df,rootname = 'Titanic') df2tree( struct = titanic_df, rootname = 'Titanic', tool_tip = letters[1:5] )
data.frame containing the structure of the github repository https://github.com/stan-dev/example-models that contains examples to run STAN models in R from the book by Gelman and Hill 'Data Analysis Using Regression Analysis and Multilevel/Hierarchical Models'.
stan.models
stan.models
An object of class "data.frame"
data(stan.models) stan.models
data(stan.models) stan.models