自定义分页框大小和字体

Customize pagination box size and font

我正在努力实现以下目标。我有这段代码来显示 dataTableOutput:

fluidRow(column(4,
                                       dataTableOutput(outputId="table01", width = '80px')))

这是定义视觉设置的代码:

output$table01 <- DT::renderDataTable({  
  list_var <- get_mp_data()
  df <- list_var[[3]]
  if(is.null(df)){
        df <- data.frame()
  }else{
        upcolor = "lightblue"
        downcolor = "lightblue"
        col_name = "CHG"
        df <- datatable(df
                        , rownames = FALSE 
                        , caption = paste0("Pre/Post Duration")
                        , filter = 'none'
                        , options = list(scrollX = F,
                                        autoWidth = T
                                        ,pageLength = 10 # this determines how many rows we want to see per page
                                        , info = FALSE #  this will hide the "Showing 1 of 2..." at the bottom of the table -->  
                                        ,searching = FALSE  # this removes the search box  ->  
                                        ,columnDefs = list(list(width = '4', targets = c(3) ) 
                                                           ,list(width = '4', targets = c(2) )
                                                           )   # careful, column counting STARTS FROM 0 !!!!
                                        )) %>% 
              formatStyle(col_name,
                          #background = styleColorBar(range(df[, c(col_name)]), 'lightblue'),
                          background = color_from_middle(df[, c(col_name)] , downcolor,   upcolor),
                          backgroundSize = '98% 88%',
                          backgroundRepeat = 'no-repeat',
                          backgroundPosition = 'center')
  }
  return(df)
})

这个 table 几乎是完美的,但是正如您从我的屏幕截图中看到的那样,table 下方的分页框占用了大量 space 无缘无故。 有没有办法让“1”框更小?有没有办法隐藏“上一个”“下一个”字样? 非常感谢

您可以使用此 CSS 来减小按钮的大小:

CSS <- "
.dataTables_wrapper .dataTables_paginate .paginate_button {
  min-width: 0.5em !important; 
  padding: 0.1em .5em !important;
} 
"

ui <- fluidPage(
  tags$head(tags$style(HTML(CSS))),
  ...

要删除单词“previous”、“next”、“first”、“last”,您可以这样做:

datatable(mydataframe, options = 
            list(
              language = list(
                paginate = list(first="", last="", previous="", `next`="")
              )
            )
)