我使用rpivotTable
包创建了一个交互式数据透视表。但是,我发现我的用户不需要一些聚合器和renderName。我想删除它们。例如,我想从聚合器下拉菜单中删除“平均值”。
以下是我的例子:
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)
我注意到有一些相关参数称为“hiddenFromAggregators”,但我无法弄清楚如何在R / Shiny环境中应用它。
这是我找到“hiddenFromAggregators”的地方。
https://github.com/nicolaskruchten/pivottable/wiki/Parameters
答案 0 :(得分:2)
hiddenFromAggregators
参数会影响哪些数据集属性有资格用作聚合器的参数,而不是哪些聚合器可用。在rpivotTable
中传递一组自定义聚合器相当具有挑战性,但可能使用类似于此方法的方法:https://github.com/smartinsightsfromdata/rpivotTable/issues/81
首先,您需要熟悉这些文档:https://github.com/nicolaskruchten/pivottable/wiki/Aggregators
答案 1 :(得分:1)
您可能正在寻找这样的东西:
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)
有一种比逐个添加聚合器(使用完整的pivotUtilities.aggregators)更快的方法
我找不到默认聚合器的完整列表,但是您可以通过应用程序上的Web检查器(使用Google Chrome:右键单击>检查)并在控制台标签中输入$.pivotUtilities.aggregators
来获得它。