Cannot generate captions with a Plotly graph

Original question was posted on SO. I'm using Quarto and trying to display a caption below a plotly graph:

---
title: "Test"
format: html
---

Test to add caption under a plotly graph

```{r}
#| label: fig-plotly
#| fig-cap: "My figure caption here"
#| column: page-inset-right
#| echo: false
#| message: false

library(plotly)
fig <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
fig


Unfortunately, the caption does not display in the rendered document. I tried manually updating quarto inside ../RStudio/resources/app/bin/quarto/bin/tools to no avail. I also viewed the rendered html in another browser. What's interesting is that on my Linux machine using the same version of packages, the caption do render.

Here's my environment:

R> rmarkdown::find_pandoc()
$version
[1] ‘3.1.2’

$dir
[1] "C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools"

R> packageVersion('plotly')
[1] ‘4.10.1.9000’

R> sessionInfo()
R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.utf8  LC_CTYPE=English_Canada.utf8    LC_MONETARY=English_Canada.utf8 LC_NUMERIC=C                   
[5] LC_TIME=English_Canada.utf8    

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.2.3  tools_4.2.3     rstudioapi_0.14

RStudio: 2023.05.0 Build 158

Thanks a lot for the report !

This is a real issue it seems, but I reproduce it only using the dev version of knitr

Which version of knitr are you using ?

1 Like

Thanks! Unfortunately, I'm not in front of the machine that has this problem. On my Linux machine that is unaffected by the problem (i.e. captions are correctly generated):

> packageVersion("knitr") 
[1] ‘1.42’

I can confirm that the problem lies in the knitr version. With the development version ‘1.42.3’, captions are not rendered underneath a plotly graph. With either the stable version and the developmental 1.42.5, this is no longer an issue.

Many thanks for pointing me in the right direction.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.