R组合数据表DT包和迷你图包装盒图与目标值

我在DT表格中使用了迷你图,如下所示: https ://leonawicz.github.io/HtmlWidgetExamples/ex_dt_sparkline.html

简化虚拟示例如下

library(data.table) library(DT) library(sparkline) hist.A<-rnorm(100) hist.B<-rnorm(100) hist.C<-rnorm(100) current.A<-rnorm(1) current.B<-rnorm(1) current.C<-rnorm(1) #whisker should show full range of data boxval.A<-paste(quantile(hist.A,probs=c(0,0.25,0.5,0.75,1)),collapse = ",") boxval.B<-paste(quantile(hist.B,probs=c(0,0.25,0.5,0.75,1)),collapse = ",") boxval.C<-paste(quantile(hist.C,probs=c(0,0.25,0.5,0.75,1)),collapse = ",") data<-data.frame(Variable=c("A","B","C"),Current=c(current.A,current.B,current.C),boxplot=c(boxval.A,boxval.B,boxval.C)) data$boxWithTarget<-paste(data$boxplot,data$Current,Sep=",") cd <- list(list(targets = 2, render = JS("function(data, type, full){ return '' + data + '' }"))) line_string <- "type: 'line', lineColor: 'black', fillColor: '#ccc', highlightLineColor: 'orange', highlightSpotColor: 'orange'" box_string <- "type: 'box', raw:true, showOutliers:false,lineColor: 'black', whiskerColor: 'black', outlierFillColor: 'black', outlierLineColor: 'black', medianColor: 'black', boxFillColor: 'orange', boxLineColor: 'black'" cb = JS("function (oSettings, json) {\n $('.sparkSeries:not(:has(canvas))').sparkline('html', { ", line_string, " });\n $('.sparkSamples:not(:has(canvas))').sparkline('html', { ", box_string, " });\n}") d <- datatable(data.table(data), rownames = FALSE, options = list(columnDefs = cd, fnDrawCallback = cb)) d$dependencies <- append(d$dependencies, htmlwidgets:::getDependency("sparkline")) d 

我想在箱形图中使用目标值函数http://omnipotent.net/jquery.sparkline/#boxplot

由于在列级别上定义了sparkline调用,因此我无法将各个目标级别作为参数传递。

所以我需要的是一个Sparkline调用的包装函数,它将列boxWithTarget(最后一个值是目标值)中定义的6个值作为参数,并调用sparkline函数。 在虚拟代码中:

  sparkline_target(input,...) { v=strsplit(input, ",") tar=v[6] val<-paste(v[1:5],collapse=",") sparkline(val,target=tar,..) } 

对于我(有限的)理解,需要在java级别定义此包装函数。 由于我不知道如何实现这一点,任何帮助将不胜感激。 非常感谢!