diff --git a/man/format_tt.html b/man/format_tt.html index 6ac172f2..1b5c20f3 100644 --- a/man/format_tt.html +++ b/man/format_tt.html @@ -413,7 +413,7 @@

Examples

- tinytable_kfxlqqtvbu0z5iyigcyq + tinytable_lv0wqow4qsh0q7n5b4w6 @@ -433,7 +433,7 @@

Examples

- +
@@ -444,16 +444,16 @@

Examples

- - - - - + - + + + + +
9 998 9 998
9 999 10 000 9 999
10 00110 00010 001
9 998 9 999
@@ -461,12 +461,20 @@

Examples

@@ -730,7 +754,7 @@

Alignment

- +
@@ -762,12 +786,20 @@

Alignment

@@ -798,12 +830,12 @@

Alignment

- tinytable_neoj8hf5s7xadhqg7p0f + tinytable_7pz6c4vai1kjkui5lo0p @@ -821,7 +853,7 @@

Alignment

-
+
@@ -853,12 +885,20 @@

Alignment

@@ -902,7 +945,7 @@

Form - tinytable_rin44k3fuoyfebdgh8eq + tinytable_0zfkdids7bihlf2dpug1 @@ -922,7 +965,7 @@

Form
-

+
@@ -937,19 +980,19 @@

Form

- + - + - + @@ -958,12 +1001,20 @@

Form @@ -1864,7 +1987,7 @@

Math

-
143002 1.431970-08-291970-02-20 True
201399 201.401970-10-131971-09-02 True
100188 0.131970-04-301970-06-30 False
+
@@ -1885,12 +2008,20 @@

Math

@@ -1950,10 +2081,10 @@

Cells, rows, columns - tinytable_u5125syp1u5p6y6rwwv9 + tinytable_6xvw4y4mwbcmvfpr90h1 @@ -1971,7 +2102,7 @@

Cells, rows, columns -

+
@@ -2018,12 +2149,20 @@

Cells, rows, columns @@ -2054,10 +2193,10 @@

Cells, rows, columns - tinytable_zbpe1qfpwpjgg5l8wr1i + tinytable_c8qgig42425cpfw09f4u @@ -2075,7 +2214,7 @@

Cells, rows, columns -

+
@@ -2122,12 +2261,20 @@

Cells, rows, columns @@ -2158,10 +2305,10 @@

Cells, rows, columns - tinytable_o610f4xm2hbn9piul9pp + tinytable_uj4ur8sljb7ei2t5jzrp @@ -2179,7 +2326,7 @@

Cells, rows, columns -

+
@@ -2226,12 +2373,20 @@

Cells, rows, columns @@ -2276,10 +2431,10 @@

Cells, rows, columns - tinytable_2ghkt6yys7lwc9rie1tt + tinytable_1rpw08nuqj8yw3jfp5r4 @@ -2297,7 +2452,7 @@

Cells, rows, columns -

+
@@ -2344,12 +2499,20 @@

Cells, rows, columns @@ -2384,10 +2547,10 @@

Cells, rows, columns - tinytable_ym1tbdlypf7l87315wmz + tinytable_pvxiifhsgup20ozxwnrr @@ -2405,7 +2568,7 @@

Cells, rows, columns -

+
@@ -2452,12 +2615,20 @@

Cells, rows, columns @@ -2490,10 +2663,10 @@

Cells, rows, columns - tinytable_grqcjeoimkt8j2uvjht3 + tinytable_42s357whcunc6q0orkvj @@ -2511,7 +2684,7 @@

Cells, rows, columns -

+
@@ -2558,12 +2731,20 @@

Cells, rows, columns @@ -2598,11 +2781,11 @@

Cells, rows, columns - tinytable_srkvh8no2nq7dp5tz873 + tinytable_q4fqu5ty18fxe3whqpvp @@ -2620,7 +2803,7 @@

Cells, rows, columns -

+
@@ -2667,12 +2850,20 @@

Cells, rows, columns @@ -2717,10 +2908,10 @@

Colors

- tinytable_4aml03tczvck7nmtd8c0 + tinytable_cvk8deexxet28db6denu @@ -2738,7 +2929,7 @@

Colors

-
+
@@ -2785,12 +2976,20 @@

Colors

@@ -2823,10 +3022,10 @@

Fonts

- tinytable_ywa85rbnm23vppqwcpm1 + tinytable_ahnq566q1bsxgrpzlrb1 @@ -2844,7 +3043,7 @@

Fonts

-
+
@@ -2891,12 +3090,20 @@

Fonts

@@ -2934,7 +3143,7 @@

Headers

- tinytable_cyqlxtqatzdb96zte08f + tinytable_ihmqtxl0o3wq4n7vi38u @@ -2954,7 +3163,7 @@

Headers

-
+
@@ -2994,12 +3203,20 @@

Headers

+ + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
mpgcyldisphpdrat
2161601103.9
2161601103.9
22.84108933.85
21.462581103.08
+
+ + + + + + + +
+ +

When styling columns without specifying i, the headers are styled in accordance with the rest of the column:

+
+
tt(x) |> style_tt(j = 2:3, color = "white", background = "black")
+
+ + + + + + + tinytable_rbh3m1opi014se8j4on3 @@ -3046,7 +3374,7 @@

Headers

- +
@@ -3093,12 +3421,20 @@

Headers

@@ -3123,13 +3464,13 @@

Headers

Conditional styling

We can use the standard which function from Base R to create indices and apply conditional stying on rows. And we can use a regular expression in j to apply conditional styling on columns:

-
k <- mtcars[1:10, c("mpg", "am", "vs")]
-
-tt(k) |> 
-  style_tt(
-    i = which(k$am == k$vs),
-    background = "teal",
-    color = "white")
+
k <- mtcars[1:10, c("mpg", "am", "vs")]
+
+tt(k) |> 
+  style_tt(
+    i = which(k$am == k$vs),
+    background = "teal",
+    color = "white")
@@ -3137,10 +3478,10 @@

Conditional styling - tinytable_n4seo6ire18wgjfzlqom + tinytable_mgziej2wg6u6gzuiwohs @@ -3158,7 +3499,7 @@

Conditional styling -

+
@@ -3225,12 +3566,20 @@

Conditional styling @@ -3259,10 +3608,10 @@

Conditional stylingVectorized styling (heatmaps)

The color, background, and fontsize arguments are vectorized. This allows easy specification of different colors in a single call:

-
tt(x) |>
-  style_tt(
-    i = 1:4,
-    color = c("red", "blue", "green", "orange"))
+
tt(x) |>
+  style_tt(
+    i = 1:4,
+    color = c("red", "blue", "green", "orange"))
@@ -3270,13 +3619,13 @@

Vectorized sty - tinytable_f8wggvhnq70iok8osooi + tinytable_52gfejvt5xr6531vxf7l @@ -3294,7 +3643,7 @@

Vectorized sty
-

+
@@ -3341,12 +3690,20 @@

Vectorized sty @@ -3383,11 +3740,11 @@

Vectorized sty

When using a single value for a vectorized argument, it gets applied to all values:

-
tt(x) |>
-  style_tt(
-    j = 2:3,
-    color = c("orange", "green"),
-    background = "black")
+
tt(x) |>
+  style_tt(
+    j = 2:3,
+    color = c("orange", "green"),
+    background = "black")
@@ -3395,11 +3752,11 @@

Vectorized sty - tinytable_wdbcm4995j5s1frmxvek + tinytable_g5zv16yx431eq54g86ia @@ -3417,7 +3774,7 @@

Vectorized sty
-

+
@@ -3464,12 +3821,20 @@

Vectorized sty @@ -3494,23 +3861,23 @@

Vectorized sty

We can also produce more complex heatmap-like tables:

-
# A table without header
-k <- data.frame(matrix(1:20, ncol = 5))
-colnames(k) <- NULL
-
-# 20 levels of Inferno colors
-bg <- hcl.colors(20, "Inferno")
-fg <- ifelse(as.matrix(k) < 17, tail(bg, 1), head(bg, 1))
-fs <- 1:20
-
-tt(k, width = .5, theme = "void") |>
-  style_tt(j = 1:5, align = "ccccc") |>
-  style_tt(
-    i = 1:4,
-    j = 1:5,
-    color = fg,
-    background = bg,
-    fontsize = fs)
+
# A table without header
+k <- data.frame(matrix(1:20, ncol = 5))
+colnames(k) <- NULL
+
+# 20 levels of Inferno colors
+bg <- hcl.colors(20, "Inferno")
+fg <- ifelse(as.matrix(k) < 17, tail(bg, 1), head(bg, 1))
+fs <- 1:20
+
+tt(k, width = .5, theme = "void") |>
+  style_tt(j = 1:5, align = "ccccc") |>
+  style_tt(
+    i = 1:4,
+    j = 1:5,
+    color = fg,
+    background = bg,
+    fontsize = fs)
@@ -3518,30 +3885,30 @@

Vectorized sty - tinytable_0krevf3tqvirpr2q0axi + tinytable_610z5mtxo9fm7dmdd9pr @@ -3559,7 +3926,7 @@

Vectorized sty
-

+
@@ -3599,12 +3966,20 @@

Vectorized sty @@ -3668,13 +4043,13 @@

Groups and labels

Rows

The i argument accepts a named list of integers. The numbers identify the positions where row group labels are to be inserted. The names includes the text that should be inserted:

-
dat <- mtcars[1:9, 1:8]
-
-tt(dat) |>
-  group_tt(i = list(
-    "I like (fake) hamburgers" = 3,
-    "She prefers halloumi" = 4,
-    "They love tofu" = 7))
+
dat <- mtcars[1:9, 1:8]
+
+tt(dat) |>
+  group_tt(i = list(
+    "I like (fake) hamburgers" = 3,
+    "She prefers halloumi" = 4,
+    "They love tofu" = 7))
@@ -3682,10 +4057,10 @@

Rows

- tinytable_d4hsa030xwn4wqmo2nzd + tinytable_izb3lururv2rsa598kw2 @@ -3703,7 +4078,7 @@

Rows

-
+
@@ -3815,12 +4190,20 @@

Rows

@@ -3852,18 +4235,18 @@

Rows

We can style group rows in the same way as regular rows:

-
tt(dat) |> 
-  group_tt(
-    i = list(
-      "I like (fake) hamburgers" = 3,
-      "She prefers halloumi" = 4,
-      "They love tofu" = 7)) |>
-  style_tt(
-    i = c(3, 5, 9),
-    align = "c",
-    color = "white",
-    background = "gray",
-    bold = TRUE)
+
tt(dat) |> 
+  group_tt(
+    i = list(
+      "I like (fake) hamburgers" = 3,
+      "She prefers halloumi" = 4,
+      "They love tofu" = 7)) |>
+  style_tt(
+    i = c(3, 5, 9),
+    align = "c",
+    color = "white",
+    background = "gray",
+    bold = TRUE)
@@ -3871,11 +4254,11 @@

Rows

- tinytable_1d6iqina1h0t1we3ynze + tinytable_m3yv3dkop7if8mi6fgyx @@ -3893,7 +4276,7 @@

Rows

-
+
@@ -4005,12 +4388,20 @@

Rows

@@ -4069,12 +4460,12 @@

Rows

Columns

The syntax for column groups is very similar, but we use the j argument instead. The named list specifies the labels to appear in column-spanning labels, and the values must be a vector of consecutive and non-overlapping integers that indicate which columns are associated to which labels:

-
tt(dat) |> 
-  group_tt(
-    j = list(
-      "Hamburgers" = 1:3,
-      "Halloumi" = 4:5,
-      "Tofu" = 7))
+
tt(dat) |> 
+  group_tt(
+    j = list(
+      "Hamburgers" = 1:3,
+      "Halloumi" = 4:5,
+      "Tofu" = 7))
@@ -4082,7 +4473,7 @@

Columns

- tinytable_a4w13n66ln79dbnfu7hl + tinytable_8wuzbpltjwncgr4bfoh0 @@ -4102,7 +4493,7 @@

Columns

-
+
@@ -4219,12 +4610,20 @@

Columns

@@ -4286,7 +4685,7 @@

Columns

-
Hamburgers Halloumi
+
@@ -4403,12 +4802,20 @@

Columns

@@ -4479,7 +4886,7 @@

Themes

The Bootstrap framework provides a number of built-in themes to style tables. To use them, we call bootstrapOptions() with the class argument, and we specify the Bootstrap class. A list of available Bootstrap classes can be found here: https://getbootstrap.com/docs/5.3/content/tables/

For example, to produce a “dark” table, we use the table-dark class:

-
tt(x, theme = "table table-dark")
+
tt(x, theme = "table table-dark")
@@ -4487,7 +4894,7 @@

Themes

- tinytable_e3lkfdywhezrkmmhyhez + tinytable_2qxsfqoyj0u0atqaysq7 @@ -4507,7 +4914,7 @@

Themes

-
Hamburgers Halloumi
+
@@ -4554,12 +4961,20 @@

Themes

@@ -4708,7 +5131,7 @@

CSS declarations

-
+
@@ -4755,12 +5178,20 @@

CSS declarations

@@ -4784,43 +5216,43 @@

CSS declarations

CSS rules

For more extensive customization, we can use complete CSS rules. In this example, we define several rules that apply to a new class called mytable. Then, we use the theme argument of the tt() function to ensure that our tiny table is of class mytable. Finally, we call style_bootstrap() to apply the rules with the bootstrap_css_rule argument.

-
css_rule <- "
-.mytable {
-  background: linear-gradient(45deg, #EA8D8D, #A890FE);
-  width: 600px;
-  border-collapse: collapse;
-  overflow: hidden;
-  box-shadow: 0 0 20px rgba(0,0,0,0.1);
-}
-
-.mytable th,
-.mytable td {
-  padding: 5px;
-  background-color: rgba(255,255,255,0.2);
-  color: #fff;
-}
-
-.mytable tbody tr:hover {
-  background-color: rgba(255,255,255,0.3);
-}
-
-.mytable tbody td:hover:before {
-  content: '';
-  position: absolute;
-  left: 0;
-  right: 0;
-  top: -9999px;
-  bottom: -9999px;
-  background-color: rgba(255,255,255,0.2);
-  z-index: -1;
-}
-"
-
-tt(x, theme = "table mytable", width = 2/3) |> 
-  style_tt(
-    j = 1:5,
-    align = "ccccc",
-    bootstrap_css_rule = css_rule)
+
css_rule <- "
+.mytable {
+  background: linear-gradient(45deg, #EA8D8D, #A890FE);
+  width: 600px;
+  border-collapse: collapse;
+  overflow: hidden;
+  box-shadow: 0 0 20px rgba(0,0,0,0.1);
+}
+
+.mytable th,
+.mytable td {
+  padding: 5px;
+  background-color: rgba(255,255,255,0.2);
+  color: #fff;
+}
+
+.mytable tbody tr:hover {
+  background-color: rgba(255,255,255,0.3);
+}
+
+.mytable tbody td:hover:before {
+  content: '';
+  position: absolute;
+  left: 0;
+  right: 0;
+  top: -9999px;
+  bottom: -9999px;
+  background-color: rgba(255,255,255,0.2);
+  z-index: -1;
+}
+"
+
+tt(x, theme = "table mytable", width = 2/3) |> 
+  style_tt(
+    j = 1:5,
+    align = "ccccc",
+    bootstrap_css_rule = css_rule)
@@ -4828,10 +5260,10 @@

CSS rules

- tinytable_zqq02s1ejdx44z7kbezw + tinytable_xnyrmrudkk6ow66ldbqu