Last active
March 26, 2021 11:20
-
-
Save shannonpileggi/54545cb294294ca879bd2040ebf3f816 to your computer and use it in GitHub Desktop.
Demo of DT::datatable column indexing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# libraries | |
library(tidyverse) | |
library(DT) | |
set.seed(1234) | |
# generate data | |
dat <- tibble( | |
A = runif(5, 0, 1), | |
B = runif(5, 0, 1), | |
C = runif(5, 0, 1), | |
) | |
# initial table with no formatting | |
DT::datatable(dat,rownames = FALSE) | |
# formatted table | |
# use columnDefs to center columns; columns are indexed at 0 | |
# use formatRound to round values; columns are indexed at 1 | |
DT::datatable(dat, | |
rownames = FALSE, | |
options = list(columnDefs = list( | |
list(className = 'dt-center', | |
targets = 0:2) | |
))) %>% | |
DT::formatRound(1:3, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment