我试图在一个闪亮的应用程序中更改Datatable的页脚。我可以使用以下代码复制应用程序中的错误:
dt_test <- tibble(cntry = c("A","A","B"),
city = c("X","Y","Z"),
sales = c(1000,1500,500),
score = c(1.1234,5.1234,2.1234))
footer <- sapply(dt_test, function(x) ifelse((is.numeric(x)), sum(x), ""))
sketch <- htmltools::withTags(table(
tableHeader(dt_test),
tableFooter(footer)
))
sketchR显示如下:
Error in writeImpl(text) :
Text to be written must be a length-one character vector但是,如果我直接将页脚的定义作为参数,那么它是有效的:
sketch <- htmltools::withTags(table(
tableHeader(dt_test),
tableFooter(sapply(dt_test, function(x) ifelse( (is.numeric(x)),sum(x), "" ))
)))不幸的是,我不能使用这种方法,因为聚合包含了很多业务逻辑,并且是在一个单独的函数中执行的。我在这里做错什么了?
发布于 2021-10-28 10:12:41
问题是footer是标记的名称,即<footer>标记。因此,在使用footer in htmltools::withTags时,实际上是将tags$footer (这是一个函数)传递给tableFooter,而不是将存储在向量页脚中的内容传递给tableFooter。这就是为什么您得到了错误消息,这也是当您直接传递定义时代码工作的原因。
这意味着有两个选项可以让您的代码工作:
htmltools::tags$...选项1:使用而不是 htmltools::withTags
library(tibble)
library(DT)
sketch <- htmltools::tags$table(
tableHeader(dt_test),
tableFooter(footer)
)选项2:重命名变量
footer1 <- footer
sketch <- htmltools::withTags(table(
tableHeader(dt_test),
tableFooter(footer1)
))https://stackoverflow.com/questions/69751593
复制相似问题