stats_noob
stats_noob

Reputation: 5897

R: Converting "rmarkdown" to "html" files

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

enter image description here

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

enter image description here

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): enter image description here

Instead of the desired output:

enter image description here

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

Thanks

Upvotes: 1

Views: 2584

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 388807

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

enter image description here

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.

enter image description here

Upvotes: 1

Related Questions