Search code examples
rhoverkable

Is it possible to use hover with multiple column background colors in kableExtra?


I want to specify column colors, but when I hover over them, to still be able to highlight a particular row. i.e., when hovering over a row the color changes.

In this example, the two columns with color do not change when hovering over. I would like them to change as well.

require(knitr)
require(kableExtra)
kable(mtcars, "html") %>%
  kable_styling(bootstrap_options = c("striped", "hover")) %>%
  column_spec(2, color = "white",
              background = "#ADD8E6") %>%
  column_spec(3, color = "white",
              background = "#ADBCE6")

Solution

  • Put this code in your Rmd file and the chosen color will appear when hovering over, like this:

    ---
    title: "Sales - YtD 2020"
    output: 
      flexdashboard::flex_dashboard:
      runtime: shiny       
    ---
    
    ```{r setup, include=FALSE}
    library(flexdashboard)
    
    ```
    
    ---
    <style>
    .table-hover > tbody > tr:hover { 
      background-color: #f4f442;
    }
    </style>
    
    Sales
    =======================================================================
    
    Row 
    -----------------------------------------------------------------------
    
    ### Your dashboard output