Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide Column and Row Totals in Shiny #63

Open
anu87 opened this issue Dec 8, 2016 · 8 comments
Open

Hide Column and Row Totals in Shiny #63

anu87 opened this issue Dec 8, 2016 · 8 comments

Comments

@anu87
Copy link

anu87 commented Dec 8, 2016

Hi! Is there a way to remove the row and totals from the rpivotTableOutput()? My output has 3x8 categories, so the total cells show totals for each category, which I don't want.

@smartinsightsfromdata
Copy link
Owner

According to the pivottable Q&A it is possible do what you want changing the css:

.pvtTotal, .pvtTotalLabel, .pvtGrandTotal {display: none}

You could in principle fork the package, change the css as above and use the new version: a lot of work!

What would make sense though, would be a way to change the css programmatically, i.e. on the fly.

I'm investigating...

@timelyportfolio
Copy link
Contributor

Perhaps ramnathv/htmlwidgets#231 will help.

@smartinsightsfromdata
Copy link
Owner

@timelyportfolio great suggestion!

I was hoping to be able to use the JS method described here,
but I haven't been able to change the css on the fly in javascript (see my reply), therefore I'm a bit stuck.

Any further help is very welcome!

@anu87
Copy link
Author

anu87 commented Dec 12, 2016

@smartinsightsfromdata I tried it in CSS - I added a style.css file to a folder 'www' in the project folder and then tried to add code that @XavierFlo shared. That didn't work. But if I change/add other things to the file about header and interface, it does change the Shiny output.

@smartinsightsfromdata
Copy link
Owner

I will give it a try next week, as I will be on hols :)

@smartinsightsfromdata
Copy link
Owner

@anu87 Apologies for taking so long. I didn't get around to try this, but I now posted in github (cran ongoing) a new version of rpivotTable aligned to the latest version of pivottable.

Would you be so kind to try again and report?

See also this nicolaskruchten/pivottable#538

@jangorecki
Copy link

There is subtotals argument to enable sub totals but there is no totals argument to disable totals... New totals argument could take logical of length two (recycled when length 1) to control rows/columns separately allowing to disable only row totals.
As per linked issue in pivottable js, this seems to be implemented there already, could we add support in rpivotTable function for that?

@timelyportfolio
Copy link
Contributor

@jangorecki Looks like we need to do a couple things to support rowTotals and colTotals now provided and explained in rendererOptions.

  1. update pivottable to the newest release 2.23.0
  2. add arguments rowTotals and colTotals or a recycling option as you suggest

For now, a very ugly solution would be to modify the htmlwidget as shown below.

library(rpivotTable)

rp <- rpivotTable(
 Titanic,
 rows = "Survived",
 cols = c("Class","Sex"),
 aggregatorName = "Sum as Fraction of Columns",
 vals = "Freq"
)
rp$x$params$rendererOptions <- list(table = list(rowTotals = FALSE))
htmltools::browsable(
  htmltools::attachDependencies(
    htmltools::tagList(
      rp
    ),
    htmltools::htmlDependency(
      name = "pivottable",
      version = "2.23.0",
      src = c(href = "https://unpkg.com/"),
      script = "[email protected]/dist/pivot.min.js",
      stylesheet = "[email protected]/dist/pivot.css"
    ),
    append = TRUE
  )
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants