htmlrr-markdownkablehuxtable

Is it possible to fix the head for a long html huxtable?


I am trying to have sticky headers like tables produced with kableExtrawhich is useful when inspecting long tables and was wondering if anyone has an idea how this may be doable with huxtable.

Here's an example Rmd to get an idea of what I mean. I'd like the huxtable header to be fixed at the top of the page when scrolling down just like in the kable.

---
output: bookdown::html_document2
---

```{r lib}
library(magrittr)
```

```{r kable}
iris %>%
  head(20) %>%
  kableExtra::kbl(caption = "a caption") %>%
  kableExtra::kable_styling(fixed_thead = TRUE)
```

```{r huxtable}
iris %>%
  head(33) %>%
  huxtable::hux() %>%
  huxtable::set_caption("a caption")
```

Solution

  • Simply set position: sticky for each th element of huxtable tables.

    ---
    output: bookdown::html_document2
    ---
    
    ```{r lib}
    library(magrittr)
    ```
    
    ```{r huxtable}
    iris %>%
      head(33) %>%
      huxtable::hux() %>%
      huxtable::set_caption("a caption")
    ```
    
    
    ```{=html}
    <style>
    
    table.huxtable th {
      position: sticky;
      top: 0;
      background: white;
    }
    
    </style>
    
    ```