Rendering a `read_csv()` with markdown hyperlinks and linebreaks into a multi-line/grid table in a quarto website

25 Views Asked by At

I have a long and complicated table containing dates and topics of my course schedule page within a quarto website.

I decided to move it into a spreadsheet for flexibly manipulating individual cells. I would like to read and render this spreadsheet in a format similar to quarto's table seen in the above link. Hence I'm trying to render the table as a pipe(or grid) table in an R chunk within a .qmd quarto website page. I tried these two things -

  • kable(format = "pipe") works but does not produce a multi-line table since "pipe" format does not support \n newline characters(?)
  • pander::pandoc.table(style = "grid") generates a grid_table but it doesn't eventually render as a html and I only see the bare markdown code after the quarto render .` command on the full website

Here's a small reprex -

``` r
options(knitr.kable.NA = "")

# ~~ Load schedule from the spreadsheet
sch <- 
  structure(list(
    
    Lec = c(1, 5), 
    Date = c("09/Jan", "25/Jan"), 
    Topic = c("Introductions and installations", 
              "R basics contd."), 
    Details = c("[slides](lecture01.Rmd) ([PDF](https://bios-538.github.io/))", 
                "for() ; function() and vectorization\n[lec5_demo](scripts/class5_demo_loops-functions.R), [lec5_practice](scripts/class5_practice_loops-functions.R)"
    )), 
    class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -2L))

# Render table with "pipe" format: \n (after vectorization) messes it up
knitr::kable(sch, format = 'pipe')
```
Lec Date Topic Details
1 09/Jan Introductions and installations slides (PDF)
5 25/Jan R basics contd. for() ; function() and vectorization
lec5_demo, lec5_practice

# Render table with pandoc.table "grid"/"rmarkdown" format: Only markdown code shows up, not final .html
pander::pandoc.table(sch, style = 'grid')
#> 
#> 
#> +-----+--------+-------------------+
#> | Lec |  Date  |       Topic       |
#> +=====+========+===================+
#> |  1  | 09/Jan | Introductions and |
#> |     |        |   installations   |
#> +-----+--------+-------------------+
#> |  5  | 25/Jan |  R basics contd.  |
#> +-----+--------+-------------------+
#> 
#> Table: Table continues below
#> 
#>  
#> 
#> +------------------------------------------------------------+
#> |                          Details                           |
#> +============================================================+
#> |                  [slides](lecture01.Rmd)                   |
#> |            ([PDF](https://bios-538.github.io/))            |
#> +------------------------------------------------------------+
#> |                   for() ; function() and                   |
#> |                       vectorization                        |
#> |    [lec5_demo](scripts/class5_demo_loops-functions.R),     |
#> | [lec5_practice](scripts/class5_practice_loops-functions.R) |
#> +------------------------------------------------------------+

Created on 2024-01-28 with reprex v2.1.0

0

There are 0 best solutions below