Search code examples
rflexdashboardgt

Left align gt table in flexdashboard


I have flexdashboard with runtime: shiny. When I create gt table it is center align, how do I make it left align? I plan to eventually render gt table.

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
   vertical_layout: fill 
   theme: 
      version: 4
      bootswatch: minty
runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
```

Row {data-height=650}
-----------------------------------------------------------------------

### Chart A

```{r}
library(gt)

gt(head(iris)) %>%
  tab_options(data_row.padding = px(1))
```

### Chart A
```{r}
```

Solution

  • One option would be to set table.align="left" in tab_options():

    ---
    title: "Untitled"
    output: 
      flexdashboard::flex_dashboard:
       vertical_layout: fill 
       theme: 
      version: 4
      bootswatch: minty
    runtime: shiny
    ---
    
    ```{r setup, include=FALSE}
    library(flexdashboard)
    ```
    
    Row {data-height=650}
    -----------------------------------------------------------------------
    
    ### Chart A
    
    <br>
    
    ```{r}
    library(gt)
    
    gt(head(iris)) %>%
      tab_options(
        data_row.padding = px(1),
        table.align = "left"
      )
    ```
    
    ### Chart B
    ```{r}
    ```
    

    enter image description here