quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.74k stars 305 forks source link

Support for online `htmlDependency()` #10339

Open cderv opened 1 month ago

cderv commented 1 month ago

Discussed in https://github.com/quarto-dev/quarto-cli/discussions/10325

Originally posted by **walkerke** July 18, 2024 ### Description I'm developing a package called __mapgl__, installable at `remotes::install_github("walkerke/mapgl")`. For licensing reasons, I'm bringing in the Mapbox GL JS JavaScript and CSS assets in via CDN rather than bundling them within the package. However, this gives Quarto problems: ````qmd --- title: "quarto_test" format: html editor: visual --- ```{r} library(mapgl) mapboxgl() ``` ```` Gives: ``` Error in FUN(X[[i]], ...) : Dependency mapbox-gl-js 3.4.0 is not disk-based Calls: .main ... dependencies_from_render -> html_dependencies_as_string -> lapply -> FUN Execution halted ``` I know this isn't a problem with my package _per se_, as disk-based assets render fine in Quarto. However - I do notice that R Markdown does not have the same problem ([see my package documentation here, which I built in R Markdown for that reason](https://walker-data.com/mapgl/)). Is there any workaround you know of to be able to pull in external assets via CDN? Or, does this merit filing an issue?
cderv commented 1 month ago

From @mcanouil there

The error does not come from Quarto. It's from htmltools::copyDependencyToDir.

This function is used inside Quarto using the default, which is mustWork = TRUE.

If TRUE and dependency does not point to a directory on disk (but rather a URL location), an error is raised. If FALSE then non-disk dependencies are returned without modification.

So right now, Quarto does not allow dependencies to be URL.

It's possible to change this behaviour, but it's not simply changing mustWork = TRUE to mustWork = FALSE.

cscheid commented 1 month ago

Can you explain a bit more what this is trying to do?

cderv commented 1 month ago

General idea is that in knitr context, some R package can brings HTML dependencies, usually JS/CSS. htmltools package have the logic behind, and knitr knows what to do with the found dependencies. htmlwidgets R package leverages the htmltools.

htmltools::htmlDependency() is the function allowing to set this required dependencies. If you look at the doc, the src can be local files, or a url. For files dependency, we need to copy them in the right place from the package to the project usually. htmltools::copyDependencyToDir() does that.

html_dependencies_as_string is building the dependency string that should be including in the resulting document. This is inspired from the one in R Markdown I believe https://github.com/rstudio/rmarkdown/blob/a9497ffa903e124a20e455e9702635ff135d9e9d/R/html_dependencies.R#L316-L324

The R Markdown version does set mustWork = FALSE which prevent the error, but it may also do specific handling in that case. This is what I need to check.

roxannecorbeil commented 1 month ago

Are there any updates for this?

mcanouil commented 1 month ago

@roxannecorbeil All relevant information has been communicated regarding the issue. If there are no updates here, it means there’s nothing new to report.