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.
What I've Tried
-
Setting output option conditionally:
if (knitr::is_html_output()) options(tinytable_print_output = "html")
Result: No effect in pkgdown examples
-
Explicitly calling print with output parameter:
tt(cd) |> print(output = "html")
Result: Error: x must be a data.frame`
-
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:
-
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.
-
Enhance knit_print.tinytable for pkgdown context:
Ensure the existing knit_print.tinytable method properly detects and handles the pkgdown rendering context.
-
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.
How to render tinytable styled HTML tables in pkgdown examples?
Description
When using
tinytablein function examples that are rendered bypkgdown::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
tinytableorpkgdown. I'll file it here, with a reference inpkgdownCurrent 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.What I've Tried
Setting output option conditionally:
Result: No effect in pkgdown examples
Explicitly calling print with output parameter:
Result: Error:
xmust be a data.frame`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:
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:
Implement a
pkgdown_print.tinytablemethod: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.htmlThis method could return the HTML representation of the table for pkgdown to embed.
Enhance
knit_print.tinytablefor pkgdown context:Ensure the existing
knit_print.tinytablemethod properly detects and handles the pkgdown rendering context.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.