ramnathv / htmlwidgets

HTML Widgets for R
http://htmlwidgets.org
Other
783 stars 207 forks source link

TOJSON_ARGS not working #188

Open jrowen opened 8 years ago

jrowen commented 8 years ago

I'm following the instructions here to override the toJSON arguments, but the override params are not being used. I can confirm that the TOJSON_ARGS attr is set on the params list passed to htmlwidgets::createWidget, but it is NULL when checked in htmlwidgets::toJSON.

  attr(params, "TOJSON_ARGS") = list(auto_unbox = FALSE)

  # create widget
  hot = htmlwidgets::createWidget(
    name = 'rhandsontable',
    params,
    width = width,
    height = height,
    package = 'rhandsontable',
    sizingPolicy = htmlwidgets::sizingPolicy(
      padding = 5,
      defaultHeight = "100%",
      defaultWidth = "100%"
    )
  )
ramnathv commented 8 years ago

Attributes are really fickle creatures, especially when you lug them around in objects. There are several R functions that don't pass attributes through. So, the better solution to your problem is to handle the unboxing on the javascript side, which should be really easy.

jcheng5 commented 8 years ago

Would it also be possible to use the preRenderHook to serialize the widget data manually? We call jsonlite::toJSON with json_verbatim=TRUE, so any data we find in there that has already been through jsonlite::toJSON should be untouched if sent through again.

jrowen commented 8 years ago

Thanks for the additional suggestions. In this case, I was able to use as.list to force the JSON to always be rendered as a list.