/
Examples2.Rmd
135 lines (106 loc) · 2.27 KB
/
Examples2.Rmd
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
title: "Examples 2"
output:
html_document:
toc: true
toc_float:
smooth_scroll: false
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(aggrid)
library(dplyr)
library(htmlwidgets)
```
## Selection
### Row Selection
#### CheckboxSelection
```{r}
head(iris, n = 10) |>
aggrid(checkboxSelection = T)
```
#### Single Selection
```{r}
head(iris, n = 10) |>
aggrid(checkboxSelection = T,rowSelection = "single",suppressRowClickSelection = T)
```
#### selectedRows
```{r}
head(iris, n = 10) |>
aggrid(checkboxSelection = T,selectedRows = 1:3)
```
#### selectedRows all
I set a convenience parameter for selecting all rows.
```{r}
head(iris, n = 10) |>
aggrid(checkboxSelection = T,selectedRows = "all")
```
## Sparkline
### line plot and column plot
```{r}
mtcars |>
dplyr::group_by(cyl) |>
dplyr::summarize(mpg_line = list(mpg)) |>
aggrid() |>
ag_col_render(mpg_line, cellRenderer = "agSparklineCellRenderer")
```
Note in the snippet above that specifying an `agSparklineCellRenderer` will display the data using the default `line` sparkline.
Sparklines are customised by supplying `sparklineOptions` to the `cellRendererParams` on the Sparkline Cell Renderer as shown below. For example:
### bar plot
```{r}
head(mtcars, n = 10) |>
dplyr::mutate(mpg_plot = mpg / max(mpg)) |>
dplyr::select(cyl, mpg_plot) |>
aggrid() |>
ag_col_render(mpg_plot,
cellRenderer = "agSparklineCellRenderer",
cellRendererParams = list(
sparklineOptions = list(
type = "bar",
valueAxisDomain = c(0, 1)
)
)
)
```
## Row group
```{r}
aggrid(iris) |>
ag_col_def(Species, rowGroup = T)
```
## Accessories
### statusBar
Default has statusBar, you can set it `FALSE` use `ag_gridOptions()`:
```{r}
aggrid(iris) |>
ag_gridOptions(statusBar = FALSE)
```
### Side Bar
```{r}
aggrid(iris) |>
ag_gridOptions(sideBar = TRUE)
```
Custom Side bar:
```{r}
aggrid(iris) |>
ag_gridOptions(sideBar = list(
toolPanels = list(
list(
id = "columns",
labelDefault = "Columns",
labelKey = "columns",
iconKey = "columns",
toolPanel = "agColumnsToolPanel"
)
)
))
```
## Charts
```{r}
aggrid(iris) |>
enable_charts()
```