smartinsightsfromdata / rpivotTable

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

renderOptions: you have to manually adjust "x$params$rendererOptions" for it to take effect #92

Open ghost opened 6 years ago

ghost commented 6 years ago

If you pass arguments to the renderOptions param, it is necessary to manually update x$params$rendererOptions(with itself?) to get it to work. Consider this example:

MYPIVOT <- rpivotTable(
    Titanic,
    rows = "Survived",
    cols = c("Sex"),
    rendererOptions = list(table = list(
        clickCallback = htmlwidgets::JS('function(e, value, filters, pivotData) {
                                        var names = [];
                                        pivotData.forEachMatchingRecord(filters,
                                        function(record){ names.push(record.Sex); });
                                        alert(names.join(\"\\n\"));
                                        }'))),
    rendererName = "Table"
)

MYPIVOT 

Run this and click on any data cells--nothing happens.

But if you add this line after your call to rpivotTable:

MYPIVOT$x$params$rendererOptions = MYPIVOT$x$params$rendererOptions[[1]]

and view MYPIVOT again, then note how clicking on a cell shows a message. I have the same experience with setting c3 renderOptions, it is always necessary to add this line after a call to rpivotTable.

Thanks.

ghost commented 6 years ago

I just submitted a PR to fix this. Thanks.