在R数据表中添加单元格边界 [英] Add Cell Borders in an R Datatable

查看:58
本文介绍了在R数据表中添加单元格边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R的新手-可以处理大图,并且在我想向其他人展示东西时努力清理边缘。

Fairly new to R - doing OK with big picture stuff, and struggling on cleaning up the edges when I want to present something to other people.

可能很简单-我只是想在一个闪亮的应用程序的数据表中为所有单元格添加单元格边框。以下是相关的代码块:

Banging my head against the wall with something that's probably pretty simple - I simply want to add cell borders - to all cells - in a datatable in a shiny app. Here's a relevant chunk of code:

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"))
                  ))
  }
  )

我一直在尝试通过Google进行跟踪,但未能找到我可以使用的解决方案。使用标签或正确的类名(至少希望如此)可能非常简单,但是我在这里迷路了。感谢我可以获得的任何帮助。

I've been trying to track it down via google, but haven't been able to hit on a solution I can get to work. It's probably something very simple with tags, or a correct class name (I hope so, at least), but I'm lost here. Appreciate any help I can get.

推荐答案

您正在寻找的功能是: formatStyle(您的DT表,列索引向量,border ='1px solid #ddd')

The function that you are looking for is : formatStyle("your DT table", "vector of column index", border = '1px solid #ddd').

您可以在此处找到可复制的示例:

You can find a reproducible example here :

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')
   })
})

必须有更优雅的方法,但是它可以工作!

There must be more elegant ways but it works !

这篇关于在R数据表中添加单元格边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆