R:转换"rmarkdown"到"html"档案 [英] R: Converting "rmarkdown" to "html" files

查看:45
本文介绍了R:转换"rmarkdown"到"html"档案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R编程语言.我正在尝试重新创建交互式仪表板".来自此网站:

然后,我删除了弹出窗口中的所有文本.我从网站(

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

现在,我想查看"仪表板并保存"仪表板作为".html"文件.我找到了另一个显示如何解决此问题的stackoverflow帖子:

而不是所需的输出:

有人可以告诉我我做错了什么,如何解决(即获得所需的输出)?

谢谢

解决方案

将文件保存在 dashboard.Rmd 中后,单击Knit->.编织到flex_dasboard

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

I am using the R programming language. I am trying to recreate the interactive "dashboard" from this website : https://beta.rstudioconnect.com/jjallaire/htmlwidgets-rbokeh-iris/htmlwidgets-rbokeh-iris.html (code is provided on this website).

First, I ran this code to access the "flexdashboard template maker" :

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

Then, I deleted all the text in the window that popped up. I copied the R code from the website (https://beta.rstudioconnect.com/jjallaire/htmlwidgets-rbokeh-iris/htmlwidgets-rbokeh-iris.html) into this window and clicked "save":

---
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)
```

This file ("dashboard.Rmd") is saved in "my documents" (which has been also set to the default working directory):

Now, I want to "view" the dashboard and "save" the dashboard as an ".html" file. I found this other stackoverflow post that shows how to solve this problem: How to convert R Markdown to HTML? I.e., What does "Knit HTML" do in Rstudio 0.96?

I tried to follow the steps in one of the answers provided on this stackoverflow post:

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

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

But this produced the following output (incorrect):

Instead of the desired output:

Can someone please show me what I am doing wrong and how can I fix this (i.e. get the desired output) ?

Thanks

解决方案

After you save the file in dashboard.Rmd, click on Knit -> Knit to flex_dasboard

This opens the dashboard template in RStudio itself. This also automatically creates a HTML file with the same name (dashboard.html) in your working directory.

这篇关于R:转换"rmarkdown"到"html"档案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆