【问题标题】:how to use knitr::spin to convert R script to html file with interactive plots如何使用 knitr::spin 将 R 脚本转换为带有交互式绘图的 html 文件
【发布时间】:2017-10-24 07:40:26
【问题描述】:

我想使用带有交互式绘图的knitr::spin 从 r 脚本生成一些 Rmarkdown 文件。但它生成的图是静态的,位于 figure 子文件夹中。我怎样才能生成保留交互式图?

这是一个例子:

#' ---
#' title: "test me"
#' output:
#'   html_notebook:
#'     code_folding: hide
#'     toc: true
#'     toc_float: true
#'     collapsed: false
#' ---
#+ warning=FALSE, echo=FALSE, message=FALSE
library(ggplot2)
library(plotly)
library(DT)

#' ## interactive cars
data(cars)
ggplotly(ggplot(data=cars,aes(x=speed,y=dist))+geom_point())

#' ## interactive table
datatable(cars)

【问题讨论】:

    标签: r plot knitr r-markdown plotly


    【解决方案1】:

    我认为这可能是因为您对同一块中的小部件进行了两次调用。当我在 RStudio 上将您的代码作为 Rmd 文件运行时,RNotebook 文件似乎堆叠了绘图(这可能就是您的意思)。

    但是,当我将两个块之间的函数调用分开时,一切看起来都很好。我生成以下输出(您可以在 RPubs 上看到):http://rpubs.com/p0bs/285465。 (要获取代码,只需单击 RPubs 文档中的下拉菜单,然后单击 SAVE RMD。)

    我希望这对你有帮助。

    【讨论】:

      猜你喜欢
      • 2018-07-05
      • 1970-01-01
      • 1970-01-01
      • 2017-10-03
      • 1970-01-01
      • 2012-02-02
      • 1970-01-01
      • 2020-10-20
      • 2013-01-30
      相关资源
      最近更新 更多