如何从 RMarkdown 中更改 scianimator 延迟参数?
How to change scianimator delay parameter from within RMarkdown?
我正在创建一个 RMarkdown 演示文稿 (ioslides),它包含一个动画。通过使用外部 header 来包含 css 和必要的 js 文件,我已经成功地使用了 hook_scianimator。但是,我不知道如何或在哪里可以修改 scianimator 参数。
在下面的示例中,我将 render() 中的 afp 参数设置为 1/19,并制作了 190 帧。所以,希望我能以每秒 19 帧的速度制作一个 10 秒的动画。
---
title: "Untitled"
author: "Author"
date: "June 23, 2015"
output:
ioslides_presentation:
includes:
in_header: header.html
self_contained: false
---
```{r, echo=FALSE}
library(knitr)
opts_knit$set(animation.fun = hook_scianimator, cache=TRUE)
knit_hooks$set(custom_plot = hook_plot_custom)
```
```{r tourr, custom_plot=TRUE, fig.show='animate', fig.ext='png', echo=FALSE, message=FALSE, out.width='2.5in',fig.num=190}
library(tourr)
tourr::render(flea[, 1:6], grand_tour(d = 2), display = display_xy(), frames=190, apf=1/19, dev="png", fig_path("%1d.png"), width=240, height=240)
Sys.sleep(1)
```
但是,当我检查由 Knit HTML 生成的 HTML 时,我看到以下内容:
<script type="text/javascript">
(function($) {
$(document).ready(function() {
var imgs = Array(190);
for (i = 0; ; i++) {
if (i == imgs.length) break;
imgs[i] = "Presentation_files/figure-html/tourr-" + (i + 1) + ".png";
}
$("#tourr").scianimator({
"images": imgs,
"delay": 1000,
"controls": ["first", "previous", "play", "next", "last", "loop", "speed"],
});
$("#tourr").scianimator("play");
});
})(jQuery);
</script>
相关组件是 "delay": 1000,
。这不是 scianimator 默认值 (that number is 250)。而且,由于一秒钟有 1000 毫秒,该延迟意味着每秒播放一帧。
我怎样才能通过我喜欢的延迟?它是否在 knitr 选项中,在文档或块级别?我应该 hand-editing 还是 HTML?我可以在 javascript 某处更改某些内容吗?
我没试过,但我想块选项 interval
应该可以,例如interval = 0.25
(250 毫秒)。
我正在创建一个 RMarkdown 演示文稿 (ioslides),它包含一个动画。通过使用外部 header 来包含 css 和必要的 js 文件,我已经成功地使用了 hook_scianimator。但是,我不知道如何或在哪里可以修改 scianimator 参数。
在下面的示例中,我将 render() 中的 afp 参数设置为 1/19,并制作了 190 帧。所以,希望我能以每秒 19 帧的速度制作一个 10 秒的动画。
---
title: "Untitled"
author: "Author"
date: "June 23, 2015"
output:
ioslides_presentation:
includes:
in_header: header.html
self_contained: false
---
```{r, echo=FALSE}
library(knitr)
opts_knit$set(animation.fun = hook_scianimator, cache=TRUE)
knit_hooks$set(custom_plot = hook_plot_custom)
```
```{r tourr, custom_plot=TRUE, fig.show='animate', fig.ext='png', echo=FALSE, message=FALSE, out.width='2.5in',fig.num=190}
library(tourr)
tourr::render(flea[, 1:6], grand_tour(d = 2), display = display_xy(), frames=190, apf=1/19, dev="png", fig_path("%1d.png"), width=240, height=240)
Sys.sleep(1)
```
但是,当我检查由 Knit HTML 生成的 HTML 时,我看到以下内容:
<script type="text/javascript">
(function($) {
$(document).ready(function() {
var imgs = Array(190);
for (i = 0; ; i++) {
if (i == imgs.length) break;
imgs[i] = "Presentation_files/figure-html/tourr-" + (i + 1) + ".png";
}
$("#tourr").scianimator({
"images": imgs,
"delay": 1000,
"controls": ["first", "previous", "play", "next", "last", "loop", "speed"],
});
$("#tourr").scianimator("play");
});
})(jQuery);
</script>
相关组件是 "delay": 1000,
。这不是 scianimator 默认值 (that number is 250)。而且,由于一秒钟有 1000 毫秒,该延迟意味着每秒播放一帧。
我怎样才能通过我喜欢的延迟?它是否在 knitr 选项中,在文档或块级别?我应该 hand-editing 还是 HTML?我可以在 javascript 某处更改某些内容吗?
我没试过,但我想块选项 interval
应该可以,例如interval = 0.25
(250 毫秒)。