问题
I want to change the core code of the highcharter in R (the requirement comes from this post). I want to change core code of the highcharts in R as I know how to modify it in javascript:
(function(H) {
(...)
H.seriesTypes.column.prototype.translate3dShapes = function() {
(...)
point.shapeType = 'cuboid';
shapeArgs.z = z;
shapeArgs.depth = point.options.depth; // changed from: shapeArgs.depth = depth;
shapeArgs.insidePlotArea = true;
(...)
};
})(Highcharts);
Calling this code using js_typeof
or such as these solutions can't be helpful anymore.
The question is *how to change the core code of the highcharter in R
回答1:
You can create your custom highchart widget using the following:
- First you can have a minimal widget with
highcharter::highchartzero()
. This custom widget only load highcharts.js. - Then add the highcharts3d using
highcharter::hc_add_dependency("highcharts-3d.js")
- Finally you can add the js as a dependency to the widget using
htmltools::htmlDependency
function (internallyhc_add_dependency
uses this function)
The code will be something like (not tested) this:
hc <- highcharter::highchartzero() %>%
highcharter::hc_add_dependency("highcharts-3d.js")
hc # see the source code and see only highcharts and highcharts-3d is loaded.
# adding depedency
dep <- htmlDependency(
name = "change-depth",
version = "1.0.0",
src = "the/folder/", # absolute path I think!
script = "your_js_script.js"
)
hc$dependencies <- c(hc$dependencies, list(dep))
hc # see the source again
hc %>% hc_add_series(...) # add the data
来源:https://stackoverflow.com/questions/47998499/how-to-modify-highcharter-htmlwidget-code