Skip to content

Commit c124eb9

Browse files
DT
1 parent 8d9ee64 commit c124eb9

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

vignettes/appearance.Rmd

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,28 @@ tab %>%
190190
set_text_color(row = 4, col = 1:ncol(.), value = 'red')
191191
```
192192

193+
194+
# `DT`
195+
196+
[The `DT` package](https://rstudio.github.io/DT/) is an interface to [the JavasScript DataTables library.](https://datatables.net/) We can create a `DT` table by using the `output` argument, and pass arguments to `modelsummary()` which will be passed forward to the `DT::datatable` to customize the output of the table. For example, let's use the `fixest` package to estimate multiple linear regression models, and the `DT` package to create a table with a "frozen" first column:
197+
198+
```{r, message = FALSE}
199+
library(fixest)
200+
201+
models <- feols(c(mpg, hp) ~ csw0(cyl, drat, am, vs, wt, carb, qsec, gear), data = mtcars)
202+
203+
modelsummary(
204+
models,
205+
output = "DT",
206+
extensions = "FixedColumns",
207+
height = 50,
208+
options = list(pageLength = 50,
209+
scrollX = TRUE,
210+
fixedColumns = list(leftColumns = 1)))
211+
```
212+
213+
214+
193215
# Themes
194216

195217
If you want to apply the same post-processing functions to your tables, you can use `modelsummary`'s theming functionality. To do so, we first create a function to post-process a table. This function must accept a table as its first argument, and include the ellipsis (`...`). Optionally, the theming function can also accept an `hrule` argument which is a vector of row positions where we insert horizontal rule, and an `output_format` which allows output format-specific customization. For inspiration, you may want to consult the default `modelsummary` themes in the [`themes.R` file of the Github repository.](https://github.com/vincentarelbundock/modelsummary)
@@ -232,7 +254,7 @@ mod <- lm(mpg ~ hp + drat, mtcars)
232254
modelsummary(mod, output = "dataframe")
233255
```
234256

235-
Imagine we want to create a table using the `DT` package, a table-drawing backend which is not currently supported by `modelsummary`. To do this, we can create a theming function:
257+
`modelsummary` supports the `DT` table-making package out of the box. But for the sake of illustration, imagine we want to create a table using the `DT` package with specific customization and options, in a repeatable fashion. To do this, we can create a theming function:
236258

237259
```{r}
238260
library(DT)
@@ -316,23 +338,3 @@ kableExtra::save_kable(tab, file = "table.tex")
316338
```
317339

318340

319-
# `DT`
320-
321-
[The `DT` package](https://rstudio.github.io/DT/) is an interface to [the JavasScript DataTables library.](https://datatables.net/) We can create a `DT` table by using the `output` argument, and pass arguments to `modelsummary()` which will be passed forward to the `DT::datatable` to customize the output of the table. For example, let's use the `fixest` package to estimate multiple linear regression models, and the `DT` package to create a table with a "frozen" first column:
322-
323-
```{r, message = FALSE}
324-
library(fixest)
325-
326-
models <- feols(c(mpg, hp) ~ csw0(cyl, drat, am, vs, wt, carb, qsec, gear), data = mtcars)
327-
328-
modelsummary(
329-
models,
330-
output = "DT",
331-
extensions = "FixedColumns",
332-
height = 50,
333-
options = list(pageLength = 50,
334-
scrollX = TRUE,
335-
fixedColumns = list(leftColumns = 1)))
336-
```
337-
338-

0 commit comments

Comments
 (0)