【问题标题】:R: Converting "rmarkdown" to "html" filesR:将“rmarkdown”转换为“html”文件
【发布时间】:2021-06-11 18:13:15
【问题描述】:

我正在使用 R 编程语言。我正在尝试从该网站重新创建交互式“仪表板”:https://beta.rstudioconnect.com/jjallaire/htmlwidgets-rbokeh-iris/htmlwidgets-rbokeh-iris.html(此网站上提供了代码)。

首先,我运行这段代码来访问“flexdashboard 模板制作器”:

library(flexdashboard)
 
rmarkdown::draft("dashboard.Rmd", template = "flex_dashboard", package = "flexdashboard")

然后,我删除了弹出窗口中的所有文本。我将网站(https://beta.rstudioconnect.com/jjallaire/htmlwidgets-rbokeh-iris/htmlwidgets-rbokeh-iris.html)中的 R 代码复制到此窗口中,然后单击“保存”:

---
title: "rbokeh iris dataset"
author: "Ryan Hafen"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    social: menu
    source_code: embed
---

```{r setup, include=FALSE}
library(rbokeh)
library(flexdashboard)
```

Column {data-width=600}
-----------------------------------------------------------------------

### Species

```{r}
figure(width = NULL, height = NULL) %>%
  ly_points(Sepal.Length, Sepal.Width, data = iris, color = Species)
# figure() %>%
#   ly_points(Sepal.Length, Sepal.Width, data = iris,
#     color = Species, glyph = Species)
```


Column {data-width=400}
-----------------------------------------------------------------------

### Species (Quantile)

```{r}
figure(width = NULL, height = NULL, legend_location = "top_left") %>%
  ly_quantile(Sepal.Length, group = Species, data = iris)
```

### Petal Width

```{r}
figure(width = NULL, height = NULL) %>%
  ly_points(Sepal.Length, Sepal.Width, data = iris,
    color = Petal.Width)
```

此文件(“dashboard.Rmd”)保存在“我的文档”中(也已设置为默认工作目录):

现在,我想“查看”仪表板并将仪表板“保存”为“.html”文件。我发现了另一个显示如何解决此问题的 stackoverflow 帖子:How to convert R Markdown to HTML? I.e., What does "Knit HTML" do in Rstudio 0.96?

我尝试按照此 stackoverflow 帖子中提供的答案之一中的步骤进行操作:

require(knitr) # required for knitting from rmd to md
require(markdown) # required for md to html 

markdownToHTML('dashboard.Rmd', 'test.html')

但这产生了以下输出(不正确):

而不是期望的输出:

谁能告诉我我做错了什么以及如何解决这个问题(即获得所需的输出)?

谢谢

【问题讨论】:

    标签: html r r-markdown data-visualization knitr


    【解决方案1】:

    将文件保存到dashboard.Rmd后,点击Knit -> Knit to flex_dasboard

    这会在 RStudio 本身中打开仪表板模板。这还会在您的工作目录中自动创建一个同名 (dashboard.html) 的 HTML 文件。

    【讨论】:

    • 感谢您的回答!有没有办法编写代码来执行“编织到 flex_dashboard”操作?我在我的视图中看不到“编织”选项:imgur.com/a/WnHBeSV。感谢您的所有帮助
    • rmarkdown::render(input = "dashboard.Rmd", output_file = "main.html") 为我工作。
    • 注意:我的电脑上只有 R studio(版本 3.4.1)(我无法升级或下载其他版本的 R,没有互联网连接或 USB 端口)。谢谢
    • 感谢您的回复!我之前尝试过相同的代码并得到以下错误:> rmarkdown::render(input = "dashboard.Rmd", output_file = "main.html") Error in yaml::yaml.load(..., eval.expr = TRUE) : Parser error: did not find expected at line 2, column 1 ...您知道导致此错误的原因是什么吗?谢谢你的帮助
    • YAML 错误是否可能是由格式错误引起的?根据我在创建初始 .rmd 文件的问题中描述的过程,我的过程是否正确?谢谢
    猜你喜欢
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 2019-12-27
    • 2018-06-03
    • 2010-11-25
    • 2013-08-24
    相关资源
    最近更新 更多