Last active
July 27, 2018 01:13
-
-
Save sebkopf/6955798 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rCharts) | |
library(rjson) # required for overwrite | |
# load rCharts and extend Nvd3 object to allow y2Axis parameters (not implemented in rCharts yet) | |
nPlot <- function(x, data, ...){ | |
Nvd3mod <- setRefClass('Nvd3mod', contains = 'Nvd3', methods = list( | |
initialize = function(){ | |
callSuper(); | |
LIB <<- get_lib('nvd3') # library name and url to parent library | |
templates$script <<- 'NVD3.html' # chart template to include y2Axis- | |
params <<- c(params, list(y2Axis = list())) | |
}, | |
y2Axis = function(..., replace = F){ | |
params$y2Axis <<- setSpec(params$y2Axis, ..., replace = replace) | |
}, | |
getPayload = function(chartId){ | |
# note cannot callSuper() because of the 'toJSON' call that hardcodes the list attributes! | |
data = toJSONArray(params$data) | |
chart = toChain(params$chart, 'chart') | |
xAxis = toChain(params$xAxis, 'chart.xAxis') | |
x2Axis = toChain(params$x2Axis, 'chart.x2Axis') | |
yAxis = toChain(params$yAxis, 'chart.yAxis') | |
y2Axis = toChain(params$y2Axis, 'chart.y2Axis') | |
opts = toJSON(params[!(names(params) %in% c('data', 'chart', 'xAxis', 'x2Axis', 'yAxis', 'y2Axis'))]) | |
list(opts = opts, xAxis = xAxis, x2Axis = x2Axis, yAxis = yAxis, y2Axis = y2Axis, data = data, | |
chart = chart, chartId = chartId) | |
} | |
)) | |
myChart <- Nvd3mod$new() | |
myChart$getChartParams(x, data, ...) | |
return(myChart$copy()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment