I'm using a package called pivottabler in R to generate pivot tables in a Shiny dashboard. The report is awesome but it takes a long time to render (10 - 15 min) which is not a good user experience. I'm aware of the different factors that influence the performance of the pivottabler package listed here: http://www.pivottabler.org.uk/articles/v08-findingandformatting.html.
After trying different approaches listed in the document I was not able to improve performance.
Below is a minimal example that uses a data frame of about 300 rows and 4 columns that takes ~25 seconds with no formatting.
library(pivottabler)
library(tidyverse)
diamonds.mod <- diamonds %>%
group_by(cut, color, clarity) %>%
summarise(avg.price = mean(price)) %>% ungroup()
startTime <- Sys.time()
pt <- PivotTable$new()
pt$addData(diamonds.mod)
pt$addColumnDataGroups("cut", addTotal=FALSE)
pt$addRowDataGroups("color", addTotal=FALSE)
pt$addRowDataGroups("clarity", addTotal=FALSE)
pt$defineCalculation(calculationName="avg.price", summariseExpression="sum(avg.price, na.rm=TRUE)")
pt$evaluatePivot()
pt$renderPivot()
endTime <- Sys.time()
endTime - startTime
My question: Does anyone know how to create such a table (above) in less time either with pivottabler or a different package? I can't just present the data in a table in tubular format as the data has many grouping levels making it hard to read in a flat table.
Thanks