【发布时间】: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