Vin*_*der 6 datatable r shiny dt
我想明确显示数据表Inf中的值而不是空白
iris[1, 1] <- Inf
DT::datatable(iris[1:2, ])
Run Code Online (Sandbox Code Playgroud)
我不想转动列信息字符以便能够对列进行排序(如果我这样做,排序将按字母顺序排列)
有任何想法吗?
编辑:
我认为可以采用这种代码:
datatable(iris[c(1:20), ], options = list(columnDefs = list(list(
targets = 5,
render = JS(
"function(data, type, row, meta) {",
"return type === 'display' && data.length > 2 ?",
"'<span title=\"' + data + '\">' + data.substr(0, 2) + '...</span>' : data;",
"}")
))))
Run Code Online (Sandbox Code Playgroud)
使用@MLavoie解决方案,它没有区别NA并且Inf
df = iris
df[1,1]<-Inf
df[2,1]<-NA
DT::datatable(df)
library(DT)
DT::datatable(df[,], options = list(columnDefs = list(list(
targets = 1,
render = JS(
"function(data, type, row, meta) {",
"return data === null ? 'Inf' : data;",
"}")
))))
Run Code Online (Sandbox Code Playgroud)
解决方案是:
options(htmlwidgets.TOJSON_ARGS = list(na = 'string'))
iris[1,1] <- NA
iris[2,1] <- Inf
DT::datatable(head(iris))
Run Code Online (Sandbox Code Playgroud)
感谢@yihui-xie 和@Jeroen:https://github.com/rstudio/DT/issues/496#issuecomment-363867449
| 归档时间: |
|
| 查看次数: |
1355 次 |
| 最近记录: |