Adding cell borders in a datatable in R can easily enhance the visual appeal of

Still relatively new to R - wrapping my head around the big concepts, but struggling with the finer details especially when it comes to presentation.

I've hit a wall trying to achieve something as simple as adding cell borders to all cells in a datatable within a shiny app. Here's a snippet of the code I'm working on:

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

I've been scouring Google for answers but haven't managed to find a solution that works yet. It must be something really straightforward like tags or the correct class name (I hope), but I'm stumped. Any guidance would be greatly appreciated.

Answer №1

If you're searching for the solution, look no further than this:

formatStyle("your data table", "column index vector", border = '1px solid #ddd')
.

To see it in action, check out this reproducible example :

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 may be more stylish ways to achieve this, but this method gets the job done!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the reason behind devtools::document() attempting to document tests?

Currently, I am developing a package (here) and have organized my tests following the testthat workflow. This involves storing my tests in the ./testthat/testthat/ directory along with a file named ./testthat/testthat.R: library(testthat) library(rpostgis ...

Starting on the Legacy 1.2.0.RC4 TideSDK: Where to Begin?

I just acquired the legacy version 1.2.0.RC4 from the official website. Now that I have it downloaded, what are the next steps? How can I begin using it? ...

Issue with Jquery Fatnav - active state not functioning properly

Currently, I am implementing a Jquery plugin known as fatNav. The documentation for the plugin can be found here: https://github.com/Glitchbone/jquery-fatNav Although everything is functioning properly, I am encountering difficulty getting my active stat ...

Having trouble centering the links in the Bootstrap navbar?

I've been struggling to center the links/tabs on my Bootstrap navbar for days now and I just can't seem to get it right. I've gone through countless similar questions without any luck. Something must be off in my code or maybe I'm not t ...

Adjust the vertical size and smoothly lower a text input field

When a user clicks on a textarea, I want it to smoothly change height to 60px and slide down in one fluid animation. Check out the JSFiddle example here: http://jsfiddle.net/MgcDU/6399/ HTML: <div class="container"> <div class="well"> ...

Display a single image on the tablet and a distinct image on the computer

Currently, I am encountering an issue with my webpage located at . The problem lies in the right upper corner where a ribbon is located. However, when viewing the page on a tablet, the ribbon overlaps with my menu. To resolve this, I thought about displa ...

I am in the process of updating the group names for the variable "age" to accurately reflect the age ranges they represent (such as 17-21), instead of the numerical values currently in place (1, 2, 3, 4, etc)

I have recently started working with R and am having trouble renaming the variable answer groupings. The values within the groups are accurate, but the names need to be changed. After changing the variable from 'factor' to 'numeric', i ...

Struggling with getting the JavaScript, scss, and CSS television animation to turn on and off properly? Seeking assistance to troubleshoot this

After finding this javascript code on Codepen and seeing that it worked perfectly in the console there, I tried to run it on my computer with jQuery but it didn't work outside of Codepen. Even when attempting to use it on JSfiddle or compile the SCSS ...

JS will reach its stopping point at the specified style.zIndex

I am currently in the process of setting up button elements. I have two scripts that correspond to different types of buttons - one script runs a simple collapse menu, while the other executes a more complex collapse by shifting depths and sliding one div ...

Comparing Boxplot to fivenum: Are the results divergent?

After executing the following code: boxplot(series, col = "orange", border = "brown") https://i.sstatic.net/WCpIk.jpg The code snippet below was then run: boxplot(d$y, col = "orange", border = "brown") abline(h = min(d$y), col = ...

Combining two rows in a dataset - beginning and ending timestamp

Hi everyone, I'm new here and hoping I'm doing this correctly! I have a dataset with 160k entries that looks like the following: Geocode Barrier.ID Device.ID City Date Time State.code 603 7 392 Por 31/01/2021 10:39:10 Deactivated ... ...

Disabling comments is creating problems with the appearance of Wordpress pages

Visit handheldtesting.com Whenever the option "disable comments" is selected in the backend, or if 'display:none:' is added <div id="respond" class="comment-respond" style="display:none;"> to the code, half of the content on the page dis ...

Steps for combining two data.tables using a time range and grouped data

My data table includes two sets of data: one that is frequently collected and another that is infrequently collected. set.seed(1) t1 <- seq(from=as.POSIXct('2014-1-1'), to=as.POSIXct('2014-6-1'), by='day') T1 <- data.ta ...

Creating a document with dynamic plots using the spin() function in knitr and saving them in a PDF file

I am feeling a bit confused about how to use the knitr package effectively. While I appreciate the spin() function for providing a quick overview of my analyses, I am facing an issue with saving specific plots in separate PDF files. For instance, I would l ...

Rearranging the stacking order of CSS pseudo-element

In the midst of creating a 3-stage progress bar using only CSS. The current design is displayed below: #progBar { background-color:#bdbdbd; padding:1.5vw; posi ...

Shift the image down to the bottom of the sidebar

This is the code for my sidebar HTML, with the side navigation bar positioned on the left: #main-container { display: table; width: 100%; height: 100%; } #sidebar { display: table-cell; width: ...

Knitr - The art of enhancing chunk output and customizing chunk settings

First and foremost, I must apologize for my lack of participation in the community. I rarely ask questions or provide answers because I prefer to search extensively before posting anything. When I do ask questions, they tend to be long and detailed. Additi ...

Tips for enhancing the appearance and functionality of an HTML form

Seeking advice on enhancing the styling of an HTML form I am developing for a course project. I'm particularly struggling to align the descriptors of radio buttons with their respective buttons. Any suggestions or guidance would be highly valued! I h ...

The default theme has not been specified in Tailwind CSS

During my recent project, I utilized React, Next.js in combination with Tailwind CSS. In this project, I delved into styling customization by implementing react-slick for a specialized slider. To achieve the desired aesthetic, I made modifications to the r ...

CSS - extend underline text decoration to include :before elements

Currently, I am utilizing a font icon from Icomoon to include an icon in the :before element of an <a>. The functionality is smooth, but the issue arises with the text-decoration: underline, which only applies to the icon and text within the anchor t ...