0

Suppose I have an .rmd document that I want to knit into an html with a large number of models:

---
title: "Example Document"
subtitle: ""
output:
  rmarkdown::html_document:
    smart: true
    theme: spacelab
    number_sections: no
    toc: true
    toc_float:
      collapsed: true
    toc_depth: 4
---

```{r echo=FALSE}
library(modelsummary)
library(purrr)
dv <- 
mtcars %>% 
  colnames() %>% 
  .[-1]

models <- 
map(.x = dv,
    ~formula(paste0(.x, "~ mpg"))) %>% 
  map(~lm(.x, data = mtcars))


modelsummary(c(models, models, models))

Is it possible to "freeze" the leftmost "variable name" column (or in other words keep it fixed) so that when I scroll to the right, the row names are always visible?

As far as I know, this feature is not available yet in kableExtra but it is perhaps possible using DT.

John-Henry
  • 1,556
  • 8
  • 20

1 Answers1

2

Are you okay with using DT? If so, you can output the modelsummary() to data.frame, and pass to DT::datatable(), using extensions="FixedColumns":

DT::datatable(
  modelsummary(c(models,models,models), output = "data.frame") %>% 
    select(-c(1,3)),
  extensions = "FixedColumns",
  options=list(scrollX = TRUE, fixedColumns = list(leftColumns = 2))
)
langtang
  • 22,248
  • 1
  • 12
  • 27
  • 2
    This is very cool, thanks for the answer. `DT` looks useful, and I will try to add official support for this package as an output format. Follow this issue if interested: https://github.com/vincentarelbundock/modelsummary/issues/553 – Vincent Sep 21 '22 at 11:51
  • Thank you for adding it as an issue I appreciate it! – John-Henry Sep 21 '22 at 19:14