在 R 数据表中添加单元格边框

ree*_*ess 1 css r shiny dt

R 相当新 - 处理大图的东西还可以,当我想向其他人展示一些东西时,努力清理边缘。

用一些可能非常简单的东西将我的头撞在墙上 - 我只是想在一个闪亮的应用程序的数据表中添加单元格边框 - 到所有单元格。这是一段相关的代码:

library(ggplot2)
library(shiny)
library(data.table)
library(DT)
library(plotly)

setwd("C:/Users/Will/Desktop/FinalPages")

lister <- read.table("PlayerList.csv", header=TRUE, quote ="", sep=",",fill = TRUE)
totals <- read.table("TotShooting.csv", header=TRUE, quote ="", sep=",",fill = TRUE)

items <- as.character(lister[[1]])

ui <- fluidPage(

  sidebarLayout(

    sidebarPanel(selectizeInput("players", "Player:", choices = items, multiple = FALSE),
    width=2

              ),

    mainPanel(h5("Total Shooting", align = "center"),
              div(dataTableOutput("tot"), style = "font-size:80%", class = 'table-condensed cell-border row-border'),
              position="center",
              width = 10)
  )
)

server <- function(input, output) {

  output$tot <- DT::renderDataTable({

    validate(
      need(input$players, ' ')
    )

    filterone <- subset(totals, Name == input$players)

    filterone <- filterone[,-1:-2]

    DT::datatable(filterone,
                  rownames = FALSE,

                  options=list(iDisplayLength=7,                    
                               bPaginate=FALSE,                  
                               bLengthChange=FALSE,                       
                               bFilter=FALSE,                                    
                               bInfo=FALSE,
                               rowid = FALSE,
                               autoWidth = FALSE,
                               ordering = FALSE,
                               scrollX = TRUE,
                               borders = TRUE,
                               columnDefs = list(list(className = 'dt-center', targets ="_all"))
                  ))
  }
  )
Run Code Online (Sandbox Code Playgroud)

我一直试图通过谷歌追踪它,但一直无法找到我可以开始工作的解决方案。使用标签或正确的类名可能非常简单(我希望如此,至少),但我在这里迷路了。感谢我能得到的任何帮助。

小智 7

您正在寻找的功能是:formatStyle("your DT table", "vector of column index", border = '1px solid #ddd')

您可以在此处找到可重现的示例:

library(shiny)
library(DT)

shinyApp(
  ui = fluidPage(
   DT::dataTableOutput("test")
  ),

 server = function(input, output, session) {
   output$test <- DT::renderDataTable({
     datatable(mtcars) %>% 
     formatStyle(c(1:dim(mtcars)[2]), border = '1px solid #ddd')
   })
})
Run Code Online (Sandbox Code Playgroud)

必须有更优雅的方法,但它有效!