r语言 - Only Table in rpivotTable



我在Shiny应用程序中使用rpivotTable包,我希望用户只能选择"表"(无图表(
RenderName参数仅用于选择默认显示。。。

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

非常感谢!

这里有多个问题。

  • 您可以通过rpivotTable()中的anonymosrenderers参数指定渲染器。我这里有JS代码表单
  • 但是,当只选择一个选项时,会出现一个错误。在这种情况下,rpivotTable()再次将参数包装在列表中(请参阅原始函数代码中的Map()调用(,并且转发到JS失败

因此,我解释了这个问题,并对函数进行了一些扩展。玩一下聚合器/渲染器,看看它的行为与最初的rpivotTable()函数有何不同。

# 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"]'))
)

相关内容

  • 没有找到相关文章

最新更新