rshinypivottable.jsrpivottable

Only Table in rpivotTable


I'm using the rpivotTable package in Shiny application and I'd like to have only the choice of 'Table' for the users (no charts)
The RenderName argument is only used to choose the default display...

output$pivot <- renderRpivotTable(
    rpivotTable(iris, 
                rendererName = "Table" )
    )

Many thanks in advance !


Solution

  • There are multiple issues here.

    Therefore, I accounted for this issue and extended the function a bit. Play around with aggregators/renderers to see how it behaves differently to the original rpivotTable() function.

    # define own function
    my_rpivotTable <- function (data, rows = NULL, cols = NULL, aggregatorName = NULL, 
              vals = NULL, rendererName = NULL, sorter = NULL, exclusions = NULL, 
              inclusions = NULL, locale = "en", subtotals = FALSE, ..., 
              width = 800, height = 600, elementId = NULL) 
    {
      if (length(intersect(class(data), c("data.frame", "data.table", 
                                          "table", "structable", "ftable"))) == 0) {
        stop("data should be a data.frame, data.table, or table", 
             call. = F)
      }
      if (length(intersect(c("table", "structable", "ftable"), 
                           class(data))) > 0) 
        data <- as.data.frame(data)
      params <- list(rows = rows, cols = cols, aggregatorName = aggregatorName, 
                     vals = vals, rendererName = rendererName, sorter = sorter, 
                     ...)
      params <- Map(function(p) {
        # added to the class check -------------------------------------------------
        if (length(p) == 1 && class(p[[1]]) != "JS_EVAL") {
          p = list(p)
        }
        return(p)
      }, params)
      par <- list(exclusions = exclusions, inclusions = inclusions)
      params <- c(params, par)
      params <- Filter(Negate(is.null), params)
      x <- list(data = data, params = params, locale = locale, 
                subtotals = subtotals)
      htmlwidgets::createWidget(name = "rpivotTable", x, width = width, 
                                height = height, elementId = elementId, package = "rpivotTable")
    }
    
    # create the pivot table
    my_rpivotTable(
      expand.grid(LETTERS, 1:3),
      aggregatorName = "Count",
      aggregators = list(Sum = htmlwidgets::JS('$.pivotUtilities.aggregators["Sum"]'),
                         Count = htmlwidgets::JS('$.pivotUtilities.aggregators["Count"]')),
      rendererName = "fancyTable",
      renderers = list(fancyTable = htmlwidgets::JS('$.pivotUtilities.renderers["Table"]'))
    
    )