Joanna
Joanna

Reputation: 673

rpivotTable: remove unnecessary aggregators

I create a interactive pivot table by using rpivotTable package. However, I found that some of aggregators and renderName are unnecessary for my users. I would like to remove them. For example, I want to remove "Average" from aggregator dropdown menu.

Here is my example:

library(shiny)
library(rpivotTable)
df <- iris

ui <- fluidPage(

fluidRow(
column(width=10, rpivotTableOutput("pivot"))
)
)

server <- function(input, output, session) {

output$pivot<-renderRpivotTable({

rpivotTable(df,
            rendererName="Heatmap",
            cols=c("Species"),
            rows=c("Petal.Width"),
            aggregatorName="Count",
            hiddenFromAggregators=["Average"]
)


 })

 }

 shinyApp(ui = ui, server = server)

I noticed that there seems some relevant parameters called "hiddenFromAggregators" but I cannot figure out how to apply it in R/Shiny environment.

Here is where I found "hiddenFromAggregators".

https://github.com/nicolaskruchten/pivottable/wiki/Parameters

Upvotes: 2

Views: 1902

Answers (2)

Jean Mallol
Jean Mallol

Reputation: 96

You may be looking for something like this :

rpivotTable(iris, 
            rendererName = "Treemap",
            cols = c("Species"),
            rows = c("Petal.Width"),
            aggregatorName = "Count",
            aggregators = list(Sum = htmlwidgets::JS('$.pivotUtilities.aggregators["Sum"]'),
                               Count = htmlwidgets::JS('$.pivotUtilities.aggregators["Count"]')),
            subtotals = TRUE)

There is probably a faster way than adding aggregators one by one (using full pivotUtilities.aggregators)

I couldn't find a full list of the default aggregators but you can get it with web inspector on your app (with Google Chrome: right click > inspect) and typing $.pivotUtilities.aggregators in the console tab.

Upvotes: 6

nicolaskruchten
nicolaskruchten

Reputation: 27370

The hiddenFromAggregators parameter affects which dataset attributes are eligible to be used as arguments to aggregators, rather than which aggregators are available. It is rather challenging in rpivotTable to pass in a custom set of aggregators but might be possible using something similar to the approach here: https://github.com/smartinsightsfromdata/rpivotTable/issues/81

You will need to familiarize yourself with the documentation here first: https://github.com/nicolaskruchten/pivottable/wiki/Aggregators

Upvotes: 3

Related Questions