R DT 按类型限制可编辑内容

R DT Limit Editable Content by Type

我有一个闪亮的应用程序,它使用 DT 及其可编辑功能。 该应用程序运行良好,但我希望 limit/verify 用户仅输入数值,这可能吗,还是我必须手动检查这些值?

MWE

目标:限制列 1:2 为数字。

DT::datatable(iris, 
              editable = list(target = "column", 
                              disable = list(columns = 3:ncol(iris))))

我做了一个pull request on the Github repository of DT which implements this feature. It is not accepted yet, hopefully it will be. In the meantime, you can restrict the editing to accept only numbers if you use my fork of DT。要安装它:remotes::install_github("stla/DT", ref = "numericedit")。要请求对某些列进行数值编辑,请设置选项 editable = list(target = "cell", numeric = INDICES),其中 INDICES 是您要对其进行数值编辑的列的索引向量。默认情况下(如果您未设置 numeric 选项),所有数字列都仅限于数字编辑。要禁用此行为,请设置 numeric = "none".