1

I would like to friendly ask that if anybody know how to make a certain variable name invisible in the selective area when using 'rpivotTable()' package in R?

For example, I build a pivot table using "UCBAdmission" data set:

# use rpivotTable to illustrate the effect
rp <- rpivotTable(UCBAdmissions, height=200)

The is the output of rp: screenshot of output

However, if user accidentally drag "Freq" to "col" or "row" area, the table will be very big but this is not what I want.

So I would like to find a way to make "Freq" invisible from the selective area. I used the code here but this can only customize the whole table but not the individual variable.

style_widget <- function(hw=NULL, style="", addl_selector="") {
stopifnot(!is.null(hw), inherits(hw, "htmlwidget"))

# use current id of htmlwidget if already specified
elementId <- hw$elementId
if(is.null(elementId)) {
# borrow htmlwidgets unique id creator
elementId <- sprintf(
  'htmlwidget-%s',
  htmlwidgets:::createWidgetId()
)
hw$elementId <- elementId
}

htmlwidgets::prependContent(
hw,
htmltools::tags$style(
  sprintf(
    "#%s %s {%s}",
    elementId,
    addl_selector,
    style
  )
 )
 )
 }


library(htmltools)
library(htmlwidgets)
library(rpivotTable)

# use rpivotTable to illustrate the effect
rp <- rpivotTable(UCBAdmissions, height=200)

browsable(
tagList(
rp,
style_widget(hw=rp, "font-family:monospace;"),
style_widget(hw=rp, "visibility:none;", "table td")
)
)

I don't know how to control the customize for individual variables. Does anyone know it or have any ideas about it?

I appreciate for any replies.

Thank you!

Best regards

nicolaskruchten
  • 26,384
  • 8
  • 83
  • 101
Joanna
  • 663
  • 7
  • 21
  • 1
    Sorry for the long delay ;). I'm the creator of the package (on top of the marvellous work of the creator of `pivottable.JS`). Thanks for using `rpivotTable`. As I'm sure you know, you can set what needs to appear on rows and cols when you launch the widget. Another alternative would be to change the dataframe, so that the relevant variable is not present. Would any of the above do the work for you? – Enzo Apr 19 '17 at 21:04
  • Hi, @Enzo. Thank you so much for helping me. I think to change the dataframe is my best choice. I might categorize the variables first so there will be no numeric variable in the selective area. In this example, if I remove "Freq" from dataframe, so it wouldn't appear in the drop-down menu (top left), but if I leave it in the drag-able area (top right), user can still drag it into row or column to make a super big table. – Joanna Apr 19 '17 at 21:21
  • 1
    You could code with an `action button` whether you want `Freq` or not. The code then filters in or out the column as appropriate. Actually, thinking about it, there is a lot you can do changing programmatically the data.frame or data.table. – Enzo Apr 19 '17 at 21:42
  • Nice! I will try it! Thank you for all advises! – Joanna Apr 19 '17 at 22:03

0 Answers0