Highlight table entry of a kable table upon clicking in a rmarkdown::beamer_presentation

Viewed 317

In a LaTex beamer presentation generated with rmarkdown::beamer_presentation, is there a way to highlight the content of a specific cell of a kableExtra table upon clicking?

highlights upon clicking

MWE

---
output:
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    latex_engine: xelatex
    slide_level: 2
---

```{r}
library(dplyr)
library(kableExtra)
```

## Table
```{r table, echo = FALSE}
my_df <- mtcars[1:4, 1:2]
my_table <- kable(my_df, booktabs = T, caption = "Table caption")
my_table
```
1 Answers

The proposed solution uses kableExtra's row_spec/column_spec/cell_spec functionality, for which several LaTex packages have to be loaded (e.g., via header-includes: ...).

enter image description here

The solution works with only one little thing remaining: the table numeration increases.
That is, the table on the first frame is numbered "1" and on the second frame with "2".
To make things really look like the added color is the only difference between both frames, the numeration would ideally be the same for both tables.

To color the rows/columns/cells as you need, see also the rmarkdown cookbook for more info on how to use row_spec/column_spec/cell_spec.

---
output:
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    latex_engine: xelatex
    slide_level: 2
header-includes:
  - \usepackage{booktabs} 
  - \usepackage{array}          
  - \usepackage{multirow}   
  - \usepackage{wrapfig}    
  - \usepackage{float}
  - \usepackage{colortbl}    
  - \usepackage{pdflscape}
  - \usepackage{tabu}
  - \usepackage{threeparttable} 
  - \usepackage{threeparttablex}
  - \usepackage[normalem]{ulem}
  - \usepackage{makecell}
---

```{r include=FALSE}
library(dplyr)
library(kableExtra)
```

## Table
```{r table, echo = FALSE}
my_df <- mtcars[1:4, 1:2]
my_table <- kable(my_df, booktabs = T, caption = "Table caption")
my_table
```

## Table {.noframenumbering}
<!-- Add "{.noframenumbering}" such that the frame number is the same on both frames -->
```{r table-with-colored-cell, echo = FALSE}
special_cell <- c(rep(F, 3), T)
colors_of_column_with_special_cell <- c(rep("black", 3), "red")

my_table %>% 
  column_spec(2, strikeout = special_cell, bold = special_cell, color = colors_of_column_with_special_cell)
```
Related