Skip to contents

Add a slicer to a previously created pivot table. This function is still experimental and might be changed/improved in upcoming releases.

Usage

wb_add_slicer(
  wb,
  x,
  dims = "A1",
  sheet = current_sheet(),
  pivot_table,
  slicer,
  params
)

Arguments

wb

A Workbook object containing a #' worksheet.

x

A data.frame that inherits the wb_data class.

dims

The worksheet cell where the pivot table is placed

sheet

A worksheet containing a #'

pivot_table

The name of a pivot table on the selected sheet

slicer

A variable used as slicer for the pivot table

params

A list of parameters to modify pivot table creation. See Details for available options.

Details

This assumes that the slicer variable initialization has happened before. Unfortunately, it is unlikely that we can guarantee this for loaded workbooks, and we strictly discourage users from attempting this. If the variable has not been initialized properly, this may cause the spreadsheet software to crash.

Possible params arguments are listed below.

  • edit_as: "twoCell" to place the slicer into the cells

  • style: "SlicerStyleLight2"

  • column_count: integer used as column count

  • caption: string used for a caption

  • sort_order: "descending" / "ascending"

  • choose: select variables in the form of a named logical vector like c(agegp = 'x > "25-34"') for the esoph dataset.

Examples

wb <- wb_workbook() %>%
  wb_add_worksheet() %>% wb_add_data(x = mtcars)

df <- wb_data(wb, sheet = 1)

wb <- wb %>%
  wb_add_pivot_table(
    df, dims = "A3", slicer = "vs", rows = "cyl", cols = "gear", data = "disp",
    pivot_table = "mtcars"
  ) %>%
  wb_add_slicer(x = df, slicer = "vs", pivot_table = "mtcars")