在 DT::datatable() 中显示 Inf

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)