2

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

nicolaskruchten
  • 26,384
  • 8
  • 83
  • 101
Joanna
  • 663
  • 7
  • 21
  • 1
    I guess the problem you are dealing with is addressed in this [issue](https://github.com/smartinsightsfromdata/rpivotTable/issues/79). – SBista Jan 22 '18 at 07:18
  • Thanks, @SBista. Yes, this is what I want. Any idea that this issue can be handled through CSS? I appreciate you. – Joanna Jan 22 '18 at 14:41

2 Answers2

6

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.

wibeasley
  • 5,000
  • 3
  • 34
  • 62
Jean Mallol
  • 86
  • 1
  • 2
  • 1
    Wow, this is awesome!!!! Thank you so much for this solution. I really appreciate it! This is exactly what I am looking for! – Joanna Oct 17 '18 at 22:29
  • I found information on aggregators here: https://pivottable.js.org/examples/onrefresh.html – Thomas Buhl Feb 22 '22 at 09:23
3

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

nicolaskruchten
  • 26,384
  • 8
  • 83
  • 101