数据表中的回调
Callback in datatable
一般来说,我想在 table 的最后一行应用样式 (border-top 和 fontWeight)。但是我的应用程序中有几个 tables 我不想在最后一行应用这种样式。我在 DT 中使用 callback( ) 来解决这个问题,但它不适用于 server = TRUE 选项。 server = FALSE 的问题是它 returns 一些奇怪的格式并且加载速度较慢。使用 server = TRUE 的任何替代解决方案?
shinyApp(
ui = fluidPage(
tags$head(
tags$style(
HTML("
table.dataTable tr:last-child td {
border-top: 1px solid #111 !important;
font-size: 13px;
font-weight:600;
color: #1c273c;
letter-spacing: .5px;
}"))),
fluidRow(
column(12,
dataTableOutput('table')
)
)
),
server = function(input, output) {
test.table <- data.frame(lapply(1:8, function(x) {1:1000}))
test.table[c(2,3,7), c(2,7,6)] <- NA
id <- which(is.na(test.table))
output$table <- renderDataTable({
DT_ignorelast <- function() DT::JS("$('table.dataTable tr:last-child td').attr('style', 'border-top : none !important; font-weight', '400');")
datatable(
test.table,
callback = DT_ignorelast())
},
server = TRUE)
}
)
是你想要的吗?
library(shiny)
library(DT)
css <- "
.lastRow {
border-top: 1px solid #111 !important;
font-size: 13px;
font-weight: 600;
color: #1c273c;
letter-spacing: .5px;
}
"
drawCallback <- JS(
"function(settings){",
" var table = this.api();",
" var nrows = table.rows().count();",
" $(table.row(nrows-1).node()).find('td').addClass('lastRow');",
"}"
)
shinyApp(
ui = fluidPage(
tags$head(
tags$style(HTML(css))
),
fluidRow(
column(12,
DTOutput('table')
)
)
),
server = function(input, output) {
test.table <- data.frame(lapply(1:8, function(x) {1:1000}))
test.table[c(2,3,7), c(2,7,6)] <- NA
id <- which(is.na(test.table))
output$table <- renderDT({
datatable(
test.table,
options = list(
drawCallback = drawCallback
)
)
},
server = TRUE)
}
)
一般来说,我想在 table 的最后一行应用样式 (border-top 和 fontWeight)。但是我的应用程序中有几个 tables 我不想在最后一行应用这种样式。我在 DT 中使用 callback( ) 来解决这个问题,但它不适用于 server = TRUE 选项。 server = FALSE 的问题是它 returns 一些奇怪的格式并且加载速度较慢。使用 server = TRUE 的任何替代解决方案?
shinyApp(
ui = fluidPage(
tags$head(
tags$style(
HTML("
table.dataTable tr:last-child td {
border-top: 1px solid #111 !important;
font-size: 13px;
font-weight:600;
color: #1c273c;
letter-spacing: .5px;
}"))),
fluidRow(
column(12,
dataTableOutput('table')
)
)
),
server = function(input, output) {
test.table <- data.frame(lapply(1:8, function(x) {1:1000}))
test.table[c(2,3,7), c(2,7,6)] <- NA
id <- which(is.na(test.table))
output$table <- renderDataTable({
DT_ignorelast <- function() DT::JS("$('table.dataTable tr:last-child td').attr('style', 'border-top : none !important; font-weight', '400');")
datatable(
test.table,
callback = DT_ignorelast())
},
server = TRUE)
}
)
是你想要的吗?
library(shiny)
library(DT)
css <- "
.lastRow {
border-top: 1px solid #111 !important;
font-size: 13px;
font-weight: 600;
color: #1c273c;
letter-spacing: .5px;
}
"
drawCallback <- JS(
"function(settings){",
" var table = this.api();",
" var nrows = table.rows().count();",
" $(table.row(nrows-1).node()).find('td').addClass('lastRow');",
"}"
)
shinyApp(
ui = fluidPage(
tags$head(
tags$style(HTML(css))
),
fluidRow(
column(12,
DTOutput('table')
)
)
),
server = function(input, output) {
test.table <- data.frame(lapply(1:8, function(x) {1:1000}))
test.table[c(2,3,7), c(2,7,6)] <- NA
id <- which(is.na(test.table))
output$table <- renderDT({
datatable(
test.table,
options = list(
drawCallback = drawCallback
)
)
},
server = TRUE)
}
)