R Add local image to title area of gt table

Viewed 36

I am trying to follow this example (Add image on title area of a table with gt package in R) to add an image to the title area of my gt table. However, this example seems to use an image hosted online.

I tried just adding the file path to the image, but then I just get an icon of an image rather than the actual image. Do I need to somehow use the local_image() in conjunction with the HTML formatted code?

Here's my code:

gt(mtcars) %>% tab_header(title = md("<img src='C:/Users/logo/logo.png' style='height:30px;'> **2014 - 2019 Salary and Playoff Appearances**&#x26BD;"), subtitle = "I am a boss")

My output: enter image description here

This also might not be exactly what I want anyway because ideally both the soccer ball and the image would cover the whole blank space on either side of the title and subtitle. As shown below by the squares:

Goal output: enter image description here

Thanks!

1 Answers

I don't know where is a problem, but in the RStudio viewer pane a local image isn't displayed.

But in the Rmarkdown it works right.

An example:

---
title: "title1"
output: html_document      
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=TRUE)
```

```{r}
library(gt)

gt(mtcars) %>% 
  tab_header(
    title = md("<img src='C://RLang//Folder//Image.png' style='height:30px;'> **2014 - 2019 Salary and Playoff Appearances**&#x26BD;"), 
    subtitle = "I am a boss")
 ```

Output:

enter image description here

Related