library(DT)
library(dplyr)
library(magrittr)
library(purrr)
library(data.tree)
library(htmlwidgets)
library(rstudioapi)

setwd(dirname(getActiveDocumentContext()$path))

source(file="../R/TT.r")
source(file="../R/TTformat.r")

load(file="../data/col_order.rda")
load(file="../data/org.rda")
load(file="../R/sysdata.rda")

colnames <- factor(c("org",org$attributesAll),
                   levels =  col_order)

standard DT::datatable

treetable(data.frame(
  date = seq(as.Date("2015-01-01"), by = "day", length.out = 5), x = 1:5
))

standard DT::datatable formatting

# apply CSS styles to columns
treetable(iris) %>%
  formatStyle('Sepal.Length', fontWeight = styleInterval(5, c('bold', 'weight'))) %>%
  formatStyle('Sepal.Width',
    color = styleInterval(3.4, c('red', 'white')),
    backgroundColor = styleInterval(3.4, c('yellow', 'gray'))
  )

treetable with default arguments

res <- treetable(org,
                 color="#FFFFFF",
                 colnames=colnames,
                 rownames=FALSE)
# remove appended js with files so easier debugging
res$append <- ""
res

treetable minimum (no args)

res<-treetable(org)
res$append <- ""
res

treetable formatting

res<-treetable(org, colnames = col_order, rownames=FALSE) %>% 
              formatRound(columns = 2, digits = 0) %>% 
              formatCurrency(columns = 3, currency = "$", digits=2, before = TRUE) %>% 
              formatPercentage(columns = 4, digits = 0) %>% 
              formatSignif(columns = 6, digits = 3, interval = 2) %>% 
              formatString(columns = 1, prefix = "org_") %>% 
              formatStyle(columns = c(7,8), valueColumns = 7,
                          backgroundColor = styleInterval(300,c('yellow','gray')))
res$append <- ""
res

data.tree with random empty attributes

lenAttr <- length(org$attributes)
org$Do(function(node){
  nAttr <- runif(1,min=1,max=lenAttr) # number of attributes to delete
  selAttr <- runif(nAttr,min=1,max=lenAttr) # selected attributes to delete
  rmAttr <- node$attributes[selAttr] %>% unique
  map(rmAttr, ~node$RemoveAttribute(.x))
})


res<-treetable(org, colnames=colnames)
res$append <- ""
res

load(file="../data/org.rda")

data.tree with empty first node

orrg <- Node$new()
orrg$AddChildNode(org)
treetable(orrg, colnames=colnames)


zielaskowski/tree-table documentation built on Sept. 28, 2024, 8:42 a.m.