saveWidget 以交互方式工作,但使用 buildVignette 时没有保存文件
saveWidget works interactively, but no file saved when using buildVignette
当我以交互方式 运行 以下代码时,会生成预期的 testFig.html
并正常运行。
suppressPackageStartupMessages(library("plotly"))
suppressPackageStartupMessages(library("htmlwidgets"))
DF <- data.frame(
x <- rnorm(50),
y <- rnorm(50),
z <- rnorm(50))
fig <- plot_ly(
name = "data", DF, x = ~x, y = ~y, z = ~z,
marker = list(size = 2.0)) %>% add_markers()
saveWidget(partial_bundle(fig), "testFig.html", knitrOptions = list(results = "show"))
但是,如果将上述代码放在小插图中,并且使用了 buildVignette
,则不会生成 testFig.html
,因此小插图中有一个占位符,表示找不到文件。不会发出任何错误或警告。小插图代码附在下面。将其保存为 Vignette.Rmd
然后执行 buildVignette("Vignette.Rmd")
以查看结果。
这是一个较大项目的最小示例,该项目在大约 5 周前运行良好,但最近开始按上述方式运行。我检查了 R
的旧版本和正在使用的包,并得到了相同的行为。结果我完全难住了。
---
title: "Test Vignette"
date: "`r Sys.Date()`"
output:
bookdown::html_document2:
toc: yes
toc_depth: 2
fig_caption: yes
number_sections: false
vignette: >
%\VignetteIndexEntry{Vignette}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
pkgdown:
as_is: true
---
```{r SetUp, echo = FALSE, eval = TRUE, results = "hide"}
# R options & configuration:
set.seed(13)
suppressPackageStartupMessages(library("knitr"))
suppressPackageStartupMessages(library("plotly"))
suppressPackageStartupMessages(library("htmlwidgets"))
# Stuff specifically for knitr:
opts_chunk$set(eval = TRUE, echo = FALSE)
```
**Test Vignette**
Trying to troubleshoot a problem with interactive diagrams not being included.
```{r testFig, results = "show"}
if (!is_latex_output()) {
DF <- data.frame(
x <- rnorm(50),
y <- rnorm(50),
z <- rnorm(50))
fig <- plot_ly(
name = "data", DF, x = ~x, y = ~y, z = ~z,
marker = list(size = 2.0)) %>%
add_markers()
saveWidget(partial_bundle(fig), "testFig.html", knitrOptions = list(results = "show"))
include_url("testFig.html")
}
> sessionInfo()
R version 4.2.0 alpha (2022-04-05 r82100)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.3.1
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] htmlwidgets_1.5.4 plotly_4.10.0 ggplot2_3.3.5 knitr_1.38
loaded via a namespace (and not attached):
[1] magrittr_2.0.3 tidyselect_1.1.2 munsell_0.5.0 viridisLite_0.4.0 colorspace_2.0-3
[6] R6_2.5.1 rlang_1.0.2 fastmap_1.1.0 fansi_1.0.3 httr_1.4.2
[11] dplyr_1.0.8 tools_4.2.0 grid_4.2.0 data.table_1.14.2 gtable_0.3.0
[16] xfun_0.30 utf8_1.2.2 cli_3.2.0 withr_2.5.0 htmltools_0.5.2
[21] ellipsis_0.3.2 lazyeval_0.2.2 digest_0.6.29 tibble_3.1.6 lifecycle_1.0.1
[26] crayon_1.5.1 tidyr_1.2.0 purrr_0.3.4 vctrs_0.4.0 glue_1.6.2
[31] compiler_4.2.0 pillar_1.7.0 generics_0.1.2 scales_1.1.1 jsonlite_1.8.0
[36] pkgconfig_2.0.3
如问题评论中所述,问题的解决方案是将生成的文件放在 vignette 目录的文件夹中。这可以防止必要的文件在使用 buildVignette
时被删除。但是,这种方法在构建和检查包时不起作用。我会问一个单独的问题。
当我以交互方式 运行 以下代码时,会生成预期的 testFig.html
并正常运行。
suppressPackageStartupMessages(library("plotly"))
suppressPackageStartupMessages(library("htmlwidgets"))
DF <- data.frame(
x <- rnorm(50),
y <- rnorm(50),
z <- rnorm(50))
fig <- plot_ly(
name = "data", DF, x = ~x, y = ~y, z = ~z,
marker = list(size = 2.0)) %>% add_markers()
saveWidget(partial_bundle(fig), "testFig.html", knitrOptions = list(results = "show"))
但是,如果将上述代码放在小插图中,并且使用了 buildVignette
,则不会生成 testFig.html
,因此小插图中有一个占位符,表示找不到文件。不会发出任何错误或警告。小插图代码附在下面。将其保存为 Vignette.Rmd
然后执行 buildVignette("Vignette.Rmd")
以查看结果。
这是一个较大项目的最小示例,该项目在大约 5 周前运行良好,但最近开始按上述方式运行。我检查了 R
的旧版本和正在使用的包,并得到了相同的行为。结果我完全难住了。
---
title: "Test Vignette"
date: "`r Sys.Date()`"
output:
bookdown::html_document2:
toc: yes
toc_depth: 2
fig_caption: yes
number_sections: false
vignette: >
%\VignetteIndexEntry{Vignette}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
pkgdown:
as_is: true
---
```{r SetUp, echo = FALSE, eval = TRUE, results = "hide"}
# R options & configuration:
set.seed(13)
suppressPackageStartupMessages(library("knitr"))
suppressPackageStartupMessages(library("plotly"))
suppressPackageStartupMessages(library("htmlwidgets"))
# Stuff specifically for knitr:
opts_chunk$set(eval = TRUE, echo = FALSE)
```
**Test Vignette**
Trying to troubleshoot a problem with interactive diagrams not being included.
```{r testFig, results = "show"}
if (!is_latex_output()) {
DF <- data.frame(
x <- rnorm(50),
y <- rnorm(50),
z <- rnorm(50))
fig <- plot_ly(
name = "data", DF, x = ~x, y = ~y, z = ~z,
marker = list(size = 2.0)) %>%
add_markers()
saveWidget(partial_bundle(fig), "testFig.html", knitrOptions = list(results = "show"))
include_url("testFig.html")
}
> sessionInfo()
R version 4.2.0 alpha (2022-04-05 r82100)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.3.1
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] htmlwidgets_1.5.4 plotly_4.10.0 ggplot2_3.3.5 knitr_1.38
loaded via a namespace (and not attached):
[1] magrittr_2.0.3 tidyselect_1.1.2 munsell_0.5.0 viridisLite_0.4.0 colorspace_2.0-3
[6] R6_2.5.1 rlang_1.0.2 fastmap_1.1.0 fansi_1.0.3 httr_1.4.2
[11] dplyr_1.0.8 tools_4.2.0 grid_4.2.0 data.table_1.14.2 gtable_0.3.0
[16] xfun_0.30 utf8_1.2.2 cli_3.2.0 withr_2.5.0 htmltools_0.5.2
[21] ellipsis_0.3.2 lazyeval_0.2.2 digest_0.6.29 tibble_3.1.6 lifecycle_1.0.1
[26] crayon_1.5.1 tidyr_1.2.0 purrr_0.3.4 vctrs_0.4.0 glue_1.6.2
[31] compiler_4.2.0 pillar_1.7.0 generics_0.1.2 scales_1.1.1 jsonlite_1.8.0
[36] pkgconfig_2.0.3
如问题评论中所述,问题的解决方案是将生成的文件放在 vignette 目录的文件夹中。这可以防止必要的文件在使用 buildVignette
时被删除。但是,这种方法在构建和检查包时不起作用。我会问一个单独的问题。