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

时间:2018-06-07 23:46:55

标签: 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"))
                  ))
  }
  )

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

1 个答案:

答案 0 :(得分:2)

您正在寻找的功能是: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')
   })
})

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