【问题标题】:How to embed ggvis interactive charts in RMarkdown?如何在 RMarkdown 中嵌入 ggvis 交互式图表?
【发布时间】:2016-10-29 19:14:47
【问题描述】:

我正在尝试将 RMarkdown 编入 html 中,此情节来自 interactivity vignette

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.

【问题讨论】:

  • 就在该页面的顶部,它告诉您Note: If you’re viewing the HTML version of this document generated with knitr, the examples will have their interactive features disabled. You’ll need to run the code in R to see and use the interactive controls. 您可以在 Shiny 或启用 Shiny 的 FlexDashboard RMarkdown 中运行它。你也可以看看 is adding some limited client-side controls.
  • @alistaire 谢谢,我注意到了,但我之前认为这是可行的,不是吗?这是否意味着ggvis.rstudio.com/interactivity.html 实际上是一个闪亮的应用程序?
  • 相信如此,或者它至少在 Shiny 服务器上运行。请注意,它的加载速度比 RStudio 的其他页面要慢一些。

标签: r r-markdown ggvis


【解决方案1】:

您必须在标题中设置“输出: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/Shiny/Shiny 文档。然后header会自动为你设置好,代码框上方的bar上会出现一个播放按钮而不是knitr按钮。另请注意,您需要在代码中包含library(ggvis),因为闪亮会以一个干净的状态开始,并且无法“看到”您已加载的包或函数。

【讨论】:

    猜你喜欢
    • 2019-06-23
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 2014-05-09
    • 2017-01-14
    • 2013-08-18
    • 1970-01-01
    • 2019-08-01
    相关资源
    最近更新 更多