如何使用R在DataTable结果中标记最后一行 [英] How to mark last row in results of DataTable using R
问题描述
我想标记(例如,粗体)使用DT包生成的数据表中的最后一行。
假设我们有一个包含虹膜数据集的表:
I would like to mark (for instance bold) the last row in Data Table generated using DT package. Let's say we have a table with the iris dataset:
library(DT)
datatable(iris)
结果:
所以我们有150行,而我想加粗仅150行。
So we have 150 rows and I would like to bold only 150 row.
编辑:
@BigDataScientist让我清除它。我有这个:
Edit: @BigDataScientist let me clear this. I have this:
output$tbl <-
DT::renderDataTable(
data() %>% # let's say iris data - it doesn't matter
bind_rows(summarise(data(), SUM = "SUM", A = sum(A), B = sum(B),
C = sum(C), D = sum(D),
E = sum(E), F = sum(F))) %>%
mutate(SUM = rowSums(.[2:6])),
extensions = 'Buttons',
options = list(
dom = 'Blfrtip',
lengthMenu = list(c(-1, 5, 10, 15, 20, 25), c('All', '5', '10', '15', '20', '25')),
buttons = list('copy',
list(extend = 'excel',
filename = 'report'),
list(extend = 'pdf',
filename = 'report'),
'print'),
rownames = FALSE,
server = FALSE
) %>%
formatStyle(
target = "row",
fontWeight = styleEqual(dim(.)[1], "bold")
)
)
因此,我想在最后一行添加粗体;在这种情况下,列的总和;到这个管道,因此一切都将合为一体(一个管道)。
So, I would like to add bolding last row; in this case, SUM of columns; to this pipeline, so everything would be in one piece (one pipeline).
推荐答案
此页面将为您提供帮助:
formatStyle(
datatable(iris), 0, target = "row",
fontWeight = styleEqual(dim(iris)[1], "bold")
)
编辑 :(另外)要求将数据作为 reactive()传递
带有闪亮管道。好吧,我只能提供一种解决方法。我不太熟悉管道,尤其是如何传递几个参数。
It was asked (in addition) for the data to be passed as reactive()
with pipes in Shiny. Well, i can only offer a workaround. I am not that familiar with pipes, especially how to pass several arguments.
shinyApp(
ui = fluidPage(fluidRow(column(12, DT::dataTableOutput('tbl')))),
server = function(input, output) {
irisReact <- reactive(iris)
dimIrisReact <- reactive(dim(iris)[1])
output$tbl = DT::renderDataTable(
irisReact() %>% datatable() %>% formatStyle(
0, target = "row",
fontWeight = styleEqual(dimIrisReact(), "bold")
)
)
}
)
这篇关于如何使用R在DataTable结果中标记最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!