github_document output and kableExtra (kable_styling) not working

I have been trying to style markdown tables (changing font size, adding scroll bars, etc) to beautifully displayed in the knitted md files that I shared via GitHub with my team. When I use kable_styling() and check it in the preview (html) locally it works. But then the md generated file just shows default table formats. I wonder what kind of additional setup should I configure.

this is my code:

---
title: User behaviour in music promotions
output:
  github_document:
    fig_width: 8
    fig_height: 6
    dev: png
editor_options: 
  chunk_output_type: console
always_allow_html: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
options(knitr.table.format = 'markdown')
#options("httr_oob_default" = TRUE)
#options(knitr.table.format = "latex")

# eval = FALSE argument, R will NOT evaluate code in a chunk
# include = FALSE, this whole code chunk is excluded in the output, but note that it will still be evaluated if eval = TRUE
# fig.align: The alignment of plots. It can be 'left', 'center', or 'right'.

library(bqr)
library(skimr)
library(ggplot2)
library(ggspotify)
library(dbplyr)
library(lubridate)
library(tidyverse)
library(here)
library(dplyr)
library(patchwork)
library(ggrepel)
library(directlabels)
library(ggbeeswarm)
library(ggjoy)
library(ggExtra)
library(funModeling)
library(purrr)
library(extrafont)
library(showtext)
library(knitr)
library(scales)
library(ggstatsplot)
library(EnvStats)
library(glue)
library(ggpmisc)
library(timetk)
library(plotly)
library(gganimate)
library(gifski)
library(png)
library(kableExtra)
library(gridExtra)
library(urltools)
library(parsedate)
library(ggside)
library(gt)
```

``` {r echo=FALSE}
df %>% 
  knitr::kable(align=rep('c', 20)) %>% 
  kable_styling(font_size = 12, 
                full_width = F,
                position = "center") %>% 
  scroll_box(width = "100%", "300px")
```

I don't think kable_styling will allow you to style a table that you output in Markdown for Github.

I don't know either if Github can support inline style or custom CSS for styling tables. You may need to export tables styled as an image to embed in your Github document.

The HTML preview you see is just a preview to check, but on Github, the markdown file will be rendered using Github own markdown renderer to HTML and we don't have access to that.

@haozhu233 Do you have additional information on using kableExtra for github outputs ? thanks:!

1 Like