gt icon indicating copy to clipboard operation
gt copied to clipboard

consequence of breaking change in htmltools `0.5.3`

Open antdurrant opened this issue 1 year ago • 4 comments

I see from the release of 0.5.3 and issue https://github.com/rstudio/htmltools/issues/305 that there was no expected use-case, so just want to flag this.

Inline printing gt::gt() tables (though not knitr::kable() tables) leaves the ``{=html} tag in the printed output.

# no problem
```{r}
x <-gt::gt(head(mtcars))

x
```
# prefix/afix

`r x`

How the tagged output looks -

Screen Shot 2022-09-09 at 14 05 19

Use case example

My frequent use case in reports is rendering tables/graphs or text or nothing, depending on available data and/or other specific conditions.

```{r}
knitr::opts_chunk$set(
	echo = FALSE,
	message = FALSE,
	warning = FALSE
)

output_fun <- function(x){
  if(x <.5){
  "some text"
} else if(x < .8){
  x
} # implied else NULL
}

a <- output_fun(.3)
b <- output_fun(.6)
c <- output_fun(.9)
```


```{r}
a
b
c
```

`r a`

`r b`

`r c`

I don't know if this is a "normal" use-case, or whether this matches the expected behaviour on your end, or whether there is a satisfactory work-around. Seeing that there didn't seem to be an expected use-case made me think it would be reasonable to bring it to your attention.

For the time-being, I'm just going to roll-back to 0.5.2.

Many thanks for continuing to provide such excellent tools!

antdurrant avatar Sep 09 '22 05:09 antdurrant

It appears as though this problem is specific to {gt}. @rich-iannone, would you mind investigating why {gt} doesn't render properly via inline code chunks (even though things like knitr::kable() and DT::datatable() do)

cpsievert avatar Sep 12 '22 20:09 cpsievert

@rich-iannone I think the issue is that maybe inline argument in the knit_print method needs to be passed explicitly so that it gets correctly picked up by the htmltools method See about inline in https://cran.r-project.org/web/packages/knitr/vignettes/knit_print.html

About the current state with mentioned tools:

  • knitr::kable does not rely on htmltools knit_print method
  • DT::datatable() uses directly the htmltools method
  • gt has its own method before relying on htmltools one

Maybe we should move the issue to gt ?

cderv avatar Sep 14 '22 16:09 cderv

Agree this is something that can be fixed in gt. I moved this issue to https://github.com/rstudio/gt/issues/1055 in rstudio/gt.

rich-iannone avatar Sep 14 '22 16:09 rich-iannone

many thanks, all!

antdurrant avatar Sep 15 '22 01:09 antdurrant