我正在尝试从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.

最佳答案

您必须在标题中设置“输出:html_document”和“运行时:闪亮”。这对我有用:

---
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 /发光/发光文件。然后,将自动为您设置页眉,并且在代码框上方的栏中会出现一个播放按钮,而不是编织按钮。另请注意,您需要在代码中包含library(ggvis),因为Shiny将以cleas板开始,并且无法“看到”您已加载的软件包或功能。

关于r - 如何在RMarkdown中嵌入ggvis交互式图表?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40322713/

10-12 20:00