【发布时间】:2021-07-30 05:35:00
【问题描述】:
想象一下,我在一个闪亮的应用程序中使用此代码,其中使用闪亮的输入过滤列:
library(magrittr)
library(DT) # version 0.18
data_viz <- data.frame(Item = c("Milk", "Bread", "Flour"), Quantity = c(2,3,4), Price = c(4,5,6)) # Original data
data_table_viz <- data_viz[, c("Item", "Quantity")] # Filtering columns on the go using Shiny app input
datatable(data = data_table_viz) %>% formatCurrency(c("Price")) # Throws error: You specified the columns: Price, but the column names of the data are , Item, Quantity
它抛出错误: name2int(name, names, rownames) 中的错误: 您指定了列:Price,但数据的列名称是 , Item, Quantity
这个错误是可以理解的,但我想避免这个错误,而是忽略“价格”列并呈现剩余的数据。以下是一种解决方法:
datatable(data = data_table_viz) %>% formatCurrency(c("Price")[c("Price") %in% colnames(data_table_viz)])
它曾经工作到 DT 包版本 0.13,但之后停止工作。
它现在抛出错误: mapply 中的错误(FUN = f, ..., SIMPLIFY = FALSE): 零长度输入不能与非零长度输入混合
对于这个问题,是否有人有其他解决方法,或者我应该继续使用旧版本的包 DT 吗?
【问题讨论】: