Skip to content

pkgdown #624

@friendly

Description

@friendly

How to render tinytable styled HTML tables in pkgdown examples?

Description

When using tinytable in function examples that are rendered by pkgdown::build_site(), the tables appear as plain text/markdown tables rather than styled HTML tables with colors and backgrounds. This makes it difficult to showcase the visual styling capabilities of tinytable in package documentation.
I'm not sure if this is an issue for tinytable or pkgdown. I'll file it here, with a reference in pkgdown

Current Behavior

In my package VisCollin, I have a function tt.colldiag() that creates styled tables with background colors and variable font sizes:

https://github.com/friendly/VisCollin/blob/master/R/tt.colldiag.R

When I run pkgdown::build_site(), the examples execute but the output appears as plain text tables instead of rendered HTML with the styling preserved.

Image

What I've Tried

  1. Setting output option conditionally:

    if (knitr::is_html_output()) options(tinytable_print_output = "html")

    Result: No effect in pkgdown examples

  2. Explicitly calling print with output parameter:

    tt(cd) |> print(output = "html")

    Result: Error: x must be a data.frame`

  3. Checking tinytable's own pkgdown site:
    Even the tinytable documentation examples section appears to show only code, not rendered styled tables

Expected Behavior

When pkgdown renders the examples, I would expect the tinytable output to appear as styled HTML tables with:

  • Background colors
  • Font size variations
  • All other visual styling applied via style_tt()

This is similar to how htmlwidgets are handled in pkgdown examples.

Potential Solutions

Based on research into pkgdown's rendering pipeline, potential solutions could include:

  1. Implement a pkgdown_print.tinytable method:
    pkgdown provides a special pkgdown_print() generic that package authors can implement to control how objects render in pkgdown examples. See: https://pkgdown.r-lib.org/reference/pkgdown_print.html

    This method could return the HTML representation of the table for pkgdown to embed.

  2. Enhance knit_print.tinytable for pkgdown context:
    Ensure the existing knit_print.tinytable method properly detects and handles the pkgdown rendering context.

  3. Documentation guidance:
    If there's a working approach I've missed, documentation showing how to properly render styled tinytables in pkgdown examples would be helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions