smartinsightsfromdata / rpivotTable

A R wrapper for the great library pivottable
Other
284 stars 71 forks source link

Unable to get only Bar Chart and Sum in RpivotTable #94

Open Saad55555 opened 5 years ago

Saad55555 commented 5 years ago

I only want to have Table, Bar chart as RendererName and Sum coming up in AggregatorName. It is currently not working. I shall be extremely grateful for the help. Thanks

Codes:

library(rpivotTable)
rpivotTable(data =  mtcars, subtotal = FALSE,  rows = c( "cyl"),cols=c("carb"),
vals =  "mpg", 
aggregatorName = "Sum",
rendererName =  "Table",
renderers = list(Table=  htmlwidgets::JS('$.pivotUtilities.renderers["Table"]'),
                         Bar_Chart = htmlwidgets::JS('$.pivotUtilities.renderers["Bar Chart"]')),
aggregators = list(Sum = htmlwidgets::JS('$.pivotUtilities.aggregators["Sum"]')),
width="50%", height="550px")
Saad55555 commented 5 years ago

Any brilliant mind with an idea?

avsdev-cw commented 5 years ago

After looking at this, the only solution I can find involves a modification to the source code of rpivotTable. It is in fact a bug in the way the 2 parameters are handled and passed into the pivotUI() call.

I can provide a patch if needed.

Saad55555 commented 5 years ago

That would be great if you could provide the patch or update the codes. Bundle of thanks mate :)

avsdev-cw commented 5 years ago

https://github.com/avsdev-cw/rpivotTable/tree/patch-002 - you can use devtools::install_github() to install

Usage would be something like:

library(rpivotTable)
rpivotTable(
    data = mtcars,
    rows = c("cyl"),
    cols = c("carb"),
    aggregatorName = "Sum",
    vals = "mpg", 
    rendererName = "Table",
    renderers = '{"Table": $.pivotUtilities.renderers["Table"], "Bar Chart": $.pivotUtilities.c3_renderers["Bar Chart"]}',
    aggregators = '{"Sum": $.pivotUtilities.aggregators["Sum"]}',
    width = "50%",
    height = "550px")
Saad55555 commented 5 years ago

Thanks a lot, but the output is showing '0' as rendererName and aggregatorName. No options are displayed with empty table. Can you please have a look?

avsdev-cw commented 5 years ago

I've bumped the version number in that branch to 0.3.1002

Install the branch from within R/RStudio with: devtools::install_github("avsdev-cw/rpivotTable", "patch-002")

Restart R and then use library(rpivotTable) to load the new library. Use sessionInfo() to check that the version that is loaded is 0.3.1002

NOTE: this is a development build of the package and as such you should treat it with caution, especially when deploying your application. If one of the maintainers of rpivotTable would like to include the modification in the origin repository, I am happy to create a PR for them to do so.

Saad55555 commented 5 years ago

Many thanks mate :) its working perfectly now. Just one last question, is it possible to remove 'Totals' coming up in column and rows?

avsdev-cw commented 5 years ago

You can add a stylesheet with a couple of rules in it:

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

You do lose the right hand table border though...

smartinsightsfromdata commented 5 years ago

@avsdev-cw Great stuff. Would you like to submit a PR for the patch?

Saad55555 commented 5 years ago

Thanks a lot mate, is it possible for you to update the codes with stylesheet having those rules. I tried but didn't work. Regards

avsdev-cw commented 5 years ago

The CSS change would need to be done on your app. This link should help you with how to do it: https://shiny.rstudio.com/articles/css.html

AndreasPhilippi commented 4 years ago

Somehow i did not get the Version 0.3.1002. When I install the package with devtools::install_github("avsdev-cw/rpivotTable", "patch-002") and check the version by sessionInfo() i still have 0.3.0. Is there any solution for that

avsdev-cw commented 4 years ago

@AndreasPhilippi did you restart your R session before loading the library?