2

我使用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

4

2 回答 2

5

您可能正在寻找这样的东西:

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)

我找不到默认聚合器的完整列表,但您可以使用应用程序上的网络检查器(使用 Google Chrome:右键单击 > 检查)并$.pivotUtilities.aggregators在控制台选项卡中输入来获取它。

于 2018-10-17T15:23:51.020 回答
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

于 2018-02-05T14:10:57.997 回答