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

crosstalk html widget doesn't display the figure caption #1443

Open
ThierryO opened this issue Oct 9, 2023 · 3 comments
Open

crosstalk html widget doesn't display the figure caption #1443

ThierryO opened this issue Oct 9, 2023 · 3 comments
Assignees
Labels
feature a feature request or enhancement

Comments

@ThierryO
Copy link
Contributor

ThierryO commented Oct 9, 2023

A chunk with a plot_ly() gets the correct caption as fixed in #118. However, the crosstalk version gets no caption.

Minimal example

--- 
title: "A Minimal Book Example"
author: "John Doe"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output:
  bookdown::gitbook: default
---

```{r crosstalk, fig.cap = "Missing caption"}
library(crosstalk)
library(plotly)
shared_mtcars <- SharedData$new(mtcars)
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()
)
```

```{r plotly, fig.cap = "Working caption"}
plot_ly(mtcars, x = ~wt, y = ~mpg, color = ~factor(cyl)) |>
  add_markers()
```

Session info

R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS, RStudio 2023.12.0.99


Locale:
  LC_CTYPE=nl_BE.UTF-8       LC_NUMERIC=C               LC_TIME=nl_BE.UTF-8        LC_COLLATE=nl_BE.UTF-8    
  LC_MONETARY=nl_BE.UTF-8    LC_MESSAGES=nl_BE.UTF-8    LC_PAPER=nl_BE.UTF-8       LC_NAME=C                 
  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=nl_BE.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Brussels
tzcode source: system (glibc)

Package version:
  base64enc_0.1.3   bookdown_0.35     bslib_0.5.1       cachem_1.0.8      cli_3.6.1         digest_0.6.33    
  ellipsis_0.3.2    evaluate_0.22     fastmap_1.1.1     fontawesome_0.5.2 fs_1.6.3          glue_1.6.2       
  graphics_4.3.1    grDevices_4.3.1   highr_0.10        htmltools_0.5.6   jquerylib_0.1.4   jsonlite_1.8.7   
  knitr_1.44        lifecycle_1.0.3   magrittr_2.0.3    memoise_2.0.1     methods_4.3.1     mime_0.12        
  R6_2.5.1          rappdirs_0.3.3    rlang_1.1.1       rmarkdown_2.25    sass_0.4.7        stats_4.3.1      
  stringi_1.7.12    stringr_1.5.0     tinytex_0.47      tools_4.3.1       utils_4.3.1       vctrs_0.6.3      
  xfun_0.40         yaml_2.3.7  
@cderv
Copy link
Collaborator

cderv commented Oct 9, 2023

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 ?

@cderv cderv added the feature a feature request or enhancement label Oct 9, 2023
@yihui
Copy link
Member

yihui commented Oct 9, 2023

Should we look maybe into the object when attr(x, "browsable_html") == TRUE ?

We could do that.

@ThierryO
Copy link
Contributor Author

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
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants