我正在尝试将 interactivity vignette 中的 RMarkdown 编织到 html 中。 :
mtcars %>% ggvis(x = ~wt) %>%
layer_densities(
adjust = input_slider(.1, 2, value = 1, step = .1, label = "Bandwidth adjustment"),
kernel = input_select(
c("Gaussian" = "gaussian",
"Epanechnikov" = "epanechnikov",
"Rectangular" = "rectangular",
"Triangular" = "triangular",
"Biweight" = "biweight",
"Cosine" = "cosine",
"Optcosine" = "optcosine"),
label = "Kernel")
)
但我收到以下错误消息:
## Warning: Can't output dynamic/interactive ggvis plots in a knitr document.
## Generating a static (non-dynamic, non-interactive) version of the plot.
最佳答案
您必须在 header 中设置“output:html_document”和“runtime:shiny”。这对我有用:
---
title: "stackoverflow"
author: "Kári S Friðriksson"
date: "7 nóvember 2016"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggvis)
```
```{r eruptions, echo=FALSE}
mtcars %>% ggvis(x = ~wt) %>%
layer_densities(
adjust = input_slider(.1, 2, value = 1, step = .1, label = "Bandwidth adjustment"),
kernel = input_select(
c("Gaussian" = "gaussian",
"Epanechnikov" = "epanechnikov",
"Rectangular" = "rectangular",
"Triangular" = "triangular",
"Biweight" = "biweight",
"Cosine" = "cosine",
"Optcosine" = "optcosine"),
label = "Kernel")
)
```
最简单的方法是转到文件/新文件/R markdown/Shiny/Shiny 文档。然后,标题将自动为您设置,并且代码框上方的栏上将有一个播放按钮,而不是编织按钮。另请注意,您需要在代码中包含 library(ggvis)
,因为 Shiny 将从 cleas slate 开始,并且无法“查看”您已加载的包或函数。
关于r - 如何在RMarkdown中嵌入ggvis交互式图表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40322713/