'Is it possible to customize the size of rpivottable treemaps

This code works and the pivot table is drawn but the treemap is huge and I need it to render to about 50% of the current size, 500px would be fine for now. It seems to ignore the size settings. One pivot table overlaps the other when drawn.Overlapping Treemaps

output$pivot3 <- renderRpivotTable({
rpivotTable(data = dotsData,
rows="county",
cols="shortBreath",
width="500px",
height="500px",
aggregatorName = "Count",
aggregators = list(
Percentage = htmlwidgets::JS('$.pivotUtilities.aggregators["Count as Fraction of Columns"]'),
Count = htmlwidgets::JS('$.pivotUtilities.aggregators["Count"]')),
sorters="function(attr) { 
                          var sortAs = $.pivotUtilities.sortAs;
                          if (attr == \"county\") { 
                               return sortAs;
                          } 
                        }")
})


Solution 1:[1]

I left a comment not that long ago of a method in which you could control the size by changing the JS. However, I have an R-based solution now.

I forked the Cran version of this package and modified it. My version of this package does allow you to control the size of the Treemap.

To install my modified packaged, use the following:

devtools::install_github("fraupflaume/rpivotTable")

You'll call the library the same way you did with the Cran version. To modify the treemap, you need to know that this is a D3 graph. All of the other graphs in this package are C3.

The following example reflects how you would indicate a specific size for either D3 or C3. (I've included several controllable options for C3 graphs, as well.)

library(rpivotTable)

rpivotTable(mtcars, rows = c("mpg", "am"), cols = "cyl", 
            width = "90%", height = "40%",
            rendererOptions = list(
              c3 = list(legend = list(show = FALSE), 
                        data = list(labels = TRUE),
                        options = list(responsive = TRUE,
                                       maintainAspectRatio = FALSE),
                        size = list(width = "600",
                                    height = "500")),
              d3 = list(size = list(width = "500", height = "500")))) 

I expanded the viewer pane so that you could see it no longer fills the viewer.

enter image description here

This is the same view, but with the D3 controls removed.

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kat