-
Notifications
You must be signed in to change notification settings - Fork 5
/
experiments.R
120 lines (108 loc) · 2.88 KB
/
experiments.R
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
library(dataui)
rn <- rnorm(1000)
ri <- runif(1000)
dui_histogram(
binCount = 25,
components = list(
dui_barseries(rawData = rn, fill="#000"),
dui_densityseries(rawData = rn, stroke = "#000"),
dui_barseries(rawData = ri),
dui_densityseries(rawData = ri),
dui_xaxis(),
dui_yaxis()
)
)
dui_histogram(
height = 400,
width = 600,
components = list(dui_barseries(runif(1:100)))
)
dui_histogram(
height = 150,
width = 400,
binCount = 25,
renderTooltip = htmlwidgets::JS(reactR::babel_transform("
{({ event, datum, data, color }) => (
<div>
<strong style={{ color }}>{datum.bin0} to {datum.bin1}</strong>
<div><strong>count </strong>{datum.count}</div>
<div><strong>cumulative </strong>{datum.cumulative}</div>
<div><strong>density </strong>{datum.density}</div>
</div>
)}
")),
components = list(
dui_barseries(
rawData = rlnorm(1000)
)
)
)
library(dplyr)
library(reactable)
data <- chickwts %>%
group_by(feed) %>%
summarise(weight = list(weight))
binValues = hist(chickwts$weight, breaks=15, plot = FALSE)$breaks
fillColors = scales::brewer_pal(type="qual", palette="Set2")(8)
reactable(
data,
columns = list(
feed = colDef(maxWidth = 100),
weight = colDef(
minWidth = 400,
cell = function(values, index) {
dui_histogram(
height = 200,
width = 400,
binValues = binValues,
renderTooltip = htmlwidgets::JS(reactR::babel_transform("
{({ event, datum, data, color }) => (
<div>
<strong style={{ color }}>{datum.bin0} to {datum.bin1}</strong>
<div><strong>count </strong>{datum.count}</div>
<div><strong>cumulative </strong>{datum.cumulative.toFixed(0)}</div>
<div><strong>density </strong>{datum.density.toFixed(0)}</div>
</div>
)}
")),
components = list(
dui_barseries(rawData = values, fill = fillColors[index]),
dui_densityseries(rawData = values, stroke = fillColors[index], fill = fillColors[index]),
dui_xaxis()
)
)
}
)
),
width = 600
)
reactable(
data,
columns = list(
feed = colDef(maxWidth = 100),
weight = colDef(
minWidth = 400,
cell = function(values, index) {
dui_histogram(
height = 200,
width = 400,
binValues = binValues,
renderTooltip = htmlwidgets::JS(reactR::babel_transform("
{({ event, datum, data, color }) => (
// can be any react component but we will need to expose the libraries
<svg width = {100} height = {100}>
<circle cx={50} cy = {50} r= {50}/>
</svg>
)}
")),
components = list(
dui_barseries(rawData = values, fill = fillColors[index]),
dui_densityseries(rawData = values, stroke = fillColors[index], fill = fillColors[index]),
dui_xaxis(numTicks = 2)
)
)
}
)
),
width = 600
)