1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

10 Comments

thank you for your answer! Is there a way to write a code to perform the "knit to flex_dashboard" action? I can not see a "knit"option in my views : imgur.com/a/WnHBeSV . thank you for all your help
rmarkdown::render(input = "dashboard.Rmd", output_file = "main.html") works for me.
note: I only have R studio (version 3.4.1) on my computer (I can not upgrade or download other versions of R, there is no internet connection or USB ports). thank you
thank you for your reply! I tried this same code earlier and got the following error: > rmarkdown::render(input = "dashboard.Rmd", output_file = "main.html") Error in yaml::yaml.load(..., eval.expr = TRUE) : Parser error: did not find expected <document start> at line 2, column 1 ... do you know what could be causing this error? thank you for your help
Is it possible that the YAML error is being caused by a formatting error? Based on the procedure I described in my question for creating the initial .rmd file, was my procedure correct? thank you
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.