Open ThierryO opened 9 months ago
This is because bscols()
does not return an object of class htmlwidget
so it is not seen as an object to add caption too (like #118 fixed).
@yihui How could we handle that ? Should we look maybe into the object when attr(x, "browsable_html") == TRUE
?
Or rather this should be crosstalk that should add a class to the object returned by bscols()
so that it is identified as a crosstalk object we can then handle ?
Should we look maybe into the object when
attr(x, "browsable_html") == TRUE
?
We could do that.
Based on your feedback, I've found a workaround. Ugly but effective.
---
title: "A Minimal Book Example"
author: "John Doe"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output:
bookdown::gitbook: default
---
```{r crosstalk, fig.cap = "Workaround caption"}
library(crosstalk)
library(plotly)
shared_mtcars <- SharedData$new(mtcars)
x <- bscols(widths = 12,
filter_slider("hp", "Horsepower", shared_mtcars, ~hp, width = "100%"),
plot_ly(shared_mtcars, x = ~wt, y = ~mpg, color = ~factor(cyl)) |>
add_markers()
)
class(x) <- c(class(x), "htmlwidget")
x
```
A chunk with a plot_ly() gets the correct caption as fixed in #118. However, the crosstalk version gets no caption.
Minimal example
Session info