Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

figure caption with plotly not showing #5052

Closed
cderv opened this issue Mar 31, 2023 · 5 comments · Fixed by yihui/knitr#2248
Closed

figure caption with plotly not showing #5052

cderv opened this issue Mar 31, 2023 · 5 comments · Fixed by yihui/knitr#2248
Assignees
Labels
bug Something isn't working knitr
Milestone

Comments

@cderv
Copy link
Collaborator

cderv commented Mar 31, 2023

---
title: "Test"
format: html
keep-md: true
---

Test to add caption under a plotly graph

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

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

It seems we are missing some fenced div where the figure caption should have been applied

---
title: "Test"
format: html
keep-md: true
---



Test to add caption under a plotly graph


::: {.cell}


```{=html}
<! --plotly html in here -->
```

:::

I believe this is supposed to work.

I get the same results with v1.2.475 oddly. So not a 1.3 regression, unless one of the patch version introduced this.

Probably something in the knitr hooks. I'll have a look but if anyone has clues, please share

@cderv cderv added the bug Something isn't working label Mar 31, 2023
@jjallaire
Copy link
Collaborator

It's probably a change in knitr? I think we should look into this for addressing in v1.3 esp. as the problem could go deeper if its in the knir hooks layer.

@cderv cderv self-assigned this Mar 31, 2023
@cderv cderv added this to the v1.3 milestone Mar 31, 2023
@cderv
Copy link
Collaborator Author

cderv commented Mar 31, 2023

This is a change in knitr indeed but dev version of knitr that I add installed. We don't test yet against dev version and hopefully I found it now before new release. This is due to yihui/knitr@99cd65a - I'll see if I can adapt here or there.

@cderv cderv added the knitr label Mar 31, 2023
@jjallaire
Copy link
Collaborator

Great, glad we found this now!

@cderv
Copy link
Collaborator Author

cderv commented Mar 31, 2023

I gave details in yihui/knitr#2248

Basically the issue is because we made a change to support collapse = TRUE when HTML widgets in chunks, but this changed what was passed to add_html_caption() and we modify this function within knitr

add_html_caption <- function(options, x) {
if (inherits(x, 'knit_asis_htmlwidget')) {
wrap_asis_output(options, x)
} else {
x
}
}
assignInNamespace("add_html_caption", add_html_caption, ns = "knitr")

@cderv
Copy link
Collaborator Author

cderv commented Mar 31, 2023

@jjallaire we've pushed a fix in dev knitr to avoid doing the processing.

As @yihui mentions again in the PR review, we may need at some point in the furture to find a way to avoid assignInNamespace().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working knitr
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants