library(aggrid)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(htmlwidgets)Sparkline
line plot and column plot
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
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)
)
)
)
#> Warning: By default htmlwidgets set auto_unbox = TRUE so the 1 length atomic elements
#> are not send as array. So default set `valueGetter` to convert Number to Array.Row group
aggrid(iris) |>
ag_col_def(Species, rowGroup = T)Accessories
statusBar
Default has statusBar, you can set it FALSE use
ag_gridOptions():
aggrid(iris) |>
ag_gridOptions(statusBar = FALSE)Side Bar
aggrid(iris) |>
ag_gridOptions(sideBar = TRUE)Custom Side bar:
aggrid(iris) |>
ag_gridOptions(sideBar = list(
toolPanels = list(
list(
id = "columns",
labelDefault = "Columns",
labelKey = "columns",
iconKey = "columns",
toolPanel = "agColumnsToolPanel"
)
)
))Charts
aggrid(iris) |>
enable_charts()