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

Quarto fails to render htmlwidgets when running {knitr} 1.43 with Error in add_html_caption(): #5702

Closed
5 tasks done
cregouby opened this issue May 26, 2023 · 18 comments · Fixed by #5704
Closed
5 tasks done
Labels
backport bug Something isn't working knitr
Milestone

Comments

@cregouby
Copy link

cregouby commented May 26, 2023

Bug description

Hello,

Current situation

{knitr} has a recent update to v1.43 that makes rendering of R code chunks with htmlwidgets fails with

$ quarto render Reprex.Rmd 


processing file: Reprex.Rmd
1/5                
2/5 [setup]        
3/5                
4/5 [DT htmlwidget]

Quitting from lines 15-16 [DT htmlwidget] (Reprex.Rmd)
Error in `add_html_caption()`:
! unused argument (xfun::grep_sub("^[^<]*<[^>]+aria-labelledby[ ]*=[ ]*\"([^\"]+)\".*$", "\\1", x))
Backtrace:
  1. global .main()
  2. execute(...)
  3. rmarkdown::render(...)
  4. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  5. knitr:::process_file(text, output)
     ...
 14. sew(res, options)
 15. knitr:::sew.list(x, options, ...)
 16. base::lapply(x, sew, options, ...)
 17. FUN(X[[i]], ...)
 18. knitr:::sew.knit_asis(x, options, ...)
Execution halted

This is not specific to {DT}, but also occurs with other htmlwidgets related packages : {collapsibleTree}, ...

ReprEx

Reprex.qmd is the following (code chunk separator manually edited for correct rendering here):

---
title: "ReprEx htmlwidget"
format: html
---

``{r setup}
library(DT)
xfun::session_info('knitr')
``

``{r DT htmlwidget}
datatable(iris)
``

Workaround

Downgrading {knitr} to 1.42 workaround the problem :

same rendering result with knitr 1.42

$ quarto render Reprex.qmd 


processing file: Reprex.qmd
                                                                                                          
output file: Reprex.knit.md

pandoc 
  to: html
  output-file: Reprex.html
  standalone: true
  section-divs: true
  html-math-method: mathjax
  wrap: none
  default-image-extension: png
  
metadata
  document-css: false
  link-citations: true
  date-format: long
  lang: en
  title: ReprEx htmlwidget
  
Output created: Reprex.html
$ quarto check

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.3.353
      Path: /Applications/quarto/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.8.16 (Conda)
      Path: /usr/local/Caskroom/miniconda/base/envs/r-reticulate/bin/python
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with conda install jupyter

[✓] Checking R installation...........OK
      Version: 4.2.1
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.2/Resources/library
      knitr: 1.42
      rmarkdown: 2.21

[✓] Checking Knitr engine render......OK

Session Info

quarto version

$ quarto -V
1.3.353

Rstudio version

Rstudio version ( as it also occurs in Rstudio ) : RStudio 2023.03.1+446 "Cherry Blossom" Release (6e31ffc3ef2a1f81d377eeccab71ddc11cfbd29e, 2023-05-09) for macOS
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2023.03.1+446 Chrome/108.0.5359.179 Electron/22.0.3 Safari/537.36

quarto check

$ quarto check

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.3.353
      Path: /Applications/quarto/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.8.16 (Conda)
      Path: /usr/local/Caskroom/miniconda/base/envs/r-reticulate/bin/python
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with conda install jupyter

[✓] Checking R installation...........OK
      Version: 4.2.1
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.2/Resources/library
      knitr: 1.43
      rmarkdown: 2.21

[✓] Checking Knitr engine render......OK

Checklist

  • Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
  • Please format your issue so it is easier for us to read the bug report.
  • Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
  • Please document the operating system you're running. If on Linux, please provide the specific distribution.
  • Please provide the output of quarto check so we know which version of quarto and its dependencies you're running.
@cregouby cregouby added the bug Something isn't working label May 26, 2023
@giabaio
Copy link
Contributor

giabaio commented May 26, 2023

+1 I think I've seen this problem too --- and I believe the issue is #2243 in knitr. I guess updating the code to allow the aria label would have broken the previous fix discussed in #2248 in knitr

@cderv
Copy link
Collaborator

cderv commented May 26, 2023

Thanks a lot for the report. This is indeed #2243 addition that breaks with Quarto because Quarto uses add_html_caption() internals but without the new arguments.

I have a quick fix for Quarto but not sure if this is considered to be knitr to adjust or Quarto

@pachadotdev
Copy link

thanks @cderv, this saved me many headaches

@mcanouil
Copy link
Collaborator

Is this going to be backported?

@cderv
Copy link
Collaborator

cderv commented Jun 15, 2023

It has been already - see changelog on last 1.3 https://quarto.org/docs/download/

(hot fix milestone usually means backport eligible)

@mcanouil
Copy link
Collaborator

ok, I first saw the closed issue without "backport" label.

@kporkka
Copy link

kporkka commented Jul 6, 2023

Downgrading knitr to 1.42 did not resolve this issue (html widgets not working). Rmarkdown version 1.22., Ubuntu 20.04. server.

Upon render, I get:

Error in 'value[3L]`:
! Package 'knitr' version 1.43 cannot be unloaded:
Error in unloadNamespace (package) namespace 'knitr' is imported by 'rmarkdown' so cannot be unloaded

Need to downgrade Rmarkdown as well? To which version? Fix coming soon? Thanks!

@mcanouil
Copy link
Collaborator

mcanouil commented Jul 6, 2023

Why downgrade? If you can downgrade, you can upgrade knitr/rmarkdown to latest and do the same for Quarto.
The issue is fixed in the latest version as stated.

@mcanouil mcanouil removed the needs-discussion Issues that require a team-wide discussion before proceeding further label Jul 6, 2023
@cderv
Copy link
Collaborator

cderv commented Jul 6, 2023

Fix coming soon? Thanks!

Please do read earliest comment : #5702 (comment)

If you still encounter some issues on your side for something that happens to be closed as fixed, please do check really thoroughly on your side. Some advices for anyone in such situations:

Usually, we close an issue when this is fixed completely. Sometimes we may have missed some edge cases. it could happen. But in this situation, it is best after having done the above to open a new issue with a link to the other closed one. In this new issue you would provide all the required informations, including the versions of the tools.

Hope this will be helpful. It really help us be more efficient and help everyone correctly when these advices are followed. thank you !

@kporkka
Copy link

kporkka commented Jul 6, 2023

Thank you for the very helpful comments and apologies for the beginner-level question. After posting my question, I noticed the topic was closed and wrongly thought nobody will see it, hence the double post.

I am running Rstudio in a very restricted hospital datalake VM, where the user can do very little. I have private R directory in which I can install my own R packages from CRAN, but that is about it. After some weeks of waiting, the admins just updated R and Rstudio and I assumed Quarto as well. Now I noticed we have a very old Quarto install (1.0.38), so I need to file a ticket and wait.

Thanks again for helping me out, learned a lot. After quite a few years on Rmarkdown, looking forward to getting familiar with Quarto.

@mcanouil
Copy link
Collaborator

mcanouil commented Jul 6, 2023

@kporkka It seems you are running on Ubuntu.
You could install Quarto locally, as you do for R packages (assuming the linux dependencies such as wget and ca-certificates are available).

The following should install the latest stable version of Quarto into your home.

DIRECTORY="~/.local"
QUARTO_DIRECTORY="${DIRECTORY}/opt"
mkdir --parents "${QUARTO_DIRECTORY}"
ARCH=$(dpkg --print-architecture)
QUARTO_VERSION=$(wget -qO- https://quarto.org/docs/download/_download.json | grep -oP '(?<="version": ")[^"]*')
QUARTO_DL_URL="https://github.com/quarto-dev/quarto-cli/releases/download/v${QUARTO_VERSION}/quarto-${QUARTO_VERSION}-linux-${ARCH}.tar.gz"
wget --quiet "$QUARTO_DL_URL" -O quarto.tar.gz
tar -C "${QUARTO_DIRECTORY}" -xzf quarto.tar.gz
ln -fs "${QUARTO_DIRECTORY}/quarto-${QUARTO_VERSION}/bin/quarto" "${DIRECTORY}/bin/quarto"
rm -f quarto.tar.gz

Note: if quarto is not available after restarting your terminal, add PATH="$HOME/.local/bin:$PATH" to your ~/.bashrc, then source ~/.bashrc.

@kporkka
Copy link

kporkka commented Jul 6, 2023

Thanks a lot @mcanouil for your suggestion and trouble. All the outbound internet is closed, apart from selected CRAN servers. But will give it a whirl once on the server tomorrow or perhaps could try to humour some of the admins (w. coffee & candy) to help out. This seems like a nice community.

@HrishikeshHard
Copy link

HrishikeshHard commented Jul 31, 2023

Dear @mcanouil, thank you for your suggestion. Downloading quarto v. 1.3.433 on my M1 MacBook Air solved the knitr 1.43 issue. However, I followed all the steps you suggested for installing the latest version of Quarto on my server running Ubuntu 20.04.6 LTS.
This installed Quarto v. 1.3.353, not 1.3.433 (validated using quarto check)
Despite properly creating symlink and adding the path to "~/.profile" and "~/.bashrc", I am unable to render ggplotly objects using knitr 1.43.

Any help will be greatly appreciated!
Thank you!

@aito123
Copy link

aito123 commented Aug 18, 2023

Hi,
I just wanted to mention that version 1.3.353 still has the problem of unable to render htmlWidgets like DT::datatable() here a reprex of my problem.

---
title: "Timevis as qmd"
author: "Santiago Sotelo"
format: html
editor: visual
---

## Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.

## Running Code

When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

```{r}
1 + 1
```

You can add options to executable code like this

```{r}
#| echo: false
2 * 2
```

The `echo: false` option disables the printing of code (only output is displayed).

```{r}
pacman::p_load(DT, tidyverse)
```

```{r}
DT::datatable(iris)
```

If this situation is fixed in the new quarto version v1.4.322, I think it should be moved from pre-release to release because it's hard to properly install this version for macOS users.

Let me know if there is a easier solution to render my htmlwidgets with my current version of quarto. Thanks.

Here is my sessionInfo()

> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Lima
tzcode source: internal

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

loaded via a namespace (and not attached):
 [1] htmlwidgets_1.6.2 compiler_4.3.1    magrittr_2.0.3    fastmap_1.1.1     cli_3.6.1         htmltools_0.5.5   tools_4.3.1       rstudioapi_0.14   yaml_2.3.7       
[10] DT_0.28           rmarkdown_2.22    knitr_1.43        xfun_0.39         digest_0.6.31     pacman_0.5.1      rlang_1.1.1       evaluate_0.21    
> quarto::quarto_version()
[1] ‘1.3.353’

@cderv
Copy link
Collaborator

cderv commented Aug 18, 2023

I just wanted to mention that version 1.3.353 still has the problem

@aito123 please do update to latest 1.3 version (currently 1.3.450). There was already a backport of this fix to 1.3 and it has the patch already.

See https://quarto.org/docs/download/

js2264 added a commit to js2264/CancerDataSci101 that referenced this issue Sep 5, 2023
quarto 1.3.353 installed on bioc docker devel has an incompatibility with knitr when rendering HTML widgets (quarto-dev/quarto-cli#5702). Fixed in Quarto 1.3.433.
@MikkoVihtakari
Copy link

MikkoVihtakari commented Sep 19, 2023

I can confirm that updating Quarto solved the issue on Mac. Just download the file, run the installer, write quarto check in terminal (in R studio if you use that) to confirm the version got updated and rerender your document.

@zander-prinsloo
Copy link

I can also confirm that updating quarto to version 1.3.450 solved this issue on windows.

@cscheid cscheid removed this from the Hot-fix milestone Feb 1, 2024
@biocyberman
Copy link

I downloaded and install quarto 1.4 on Ubuntu 22.04 and solved the problem.

@mcanouil mcanouil added this to the v1.4 milestone Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport bug Something isn't working knitr
Projects
None yet
Development

Successfully merging a pull request may close this issue.