dui_add_deps: Add 'data-ui' Dependencies to Tag or 'htmlwidget'

Description Usage Arguments Value See Also Examples

View source: R/table_helpers.R

Description

Add 'data-ui' Dependencies to Tag or 'htmlwidget'

Usage

1
dui_add_deps(tag_htmlwidget = NULL)

Arguments

tag_htmlwidget

shiny.tag or htmlwidget to which you would like to add data-ui dependencies

Value

shiny.tag or htmlwidget

See Also

dui_chr

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
library(htmltools)

# not that you would want to do this but illustrates the usage of helper functions
browsable(
  dui_add_deps(
    tags$div(
      dui_chr(
        dui_sparkline(
          data = runif(100),
          components = list(
            dui_sparklineseries(strokeDasharray = "3,3"),
            dui_sparkpointseries(points = list("min","max"))
          )
        )
      )
    )
  )
)


library(dplyr)
library(htmltools)
library(dataui)

data("diamonds", package="ggplot2")

hist_all <- hist(diamonds$price, breaks = 20, plot = FALSE)

dat <- diamonds %>%
  group_by(cut) %>%
  summarize(
    n = n(),
    mean_price = mean(price),
    hist = list(unclass(hist(price, breaks = hist_all$breaks, plot = FALSE)))
  )

# calculate max so all sparklines use same scale
max_density <- max(unlist(lapply(dat$hist, function(x) {x$density})))

# convert hist column to character version of data-ui htmlwidget
dat <- dat %>%
  mutate(hist = lapply(hist, function(h){
    dui_chr(
      dui_sparkline(
        data = h$density,
        max = max_density,
        height = 80,
        margin = list(top = 0, bottom = 0, left = 20, right = 0),
        components = list(
          dui_sparkbarseries(),
          dui_tooltip(
            list(
              dui_sparkhorizontalrefline(
                stroke = "#ccc",
                strokeDasharray = "4,4"
              ),
              dui_sparkpointseries(
                renderLabel = htmlwidgets::JS("(d) => d ? (d*100000).toFixed(2) + '%' : null"),
                labelPosition = "right"
              )
            )
          )
        )
      )
    )
  }))

# datatable
library(DT)
DT::datatable(
  dat,
  escape = FALSE,
  options = list(
    fnDrawCallback = htmlwidgets::JS('function(){ HTMLWidgets.staticRender()}')
  )
) %>%
  formatCurrency("mean_price", digits = 0) %>%
  formatRound("n", digits = 0) %>%
  dui_add_deps()

timelyportfolio/dataui documentation built on July 15, 2020, 12:03 p.m.