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

stats_noob
  • 5,401
  • 4
  • 27
  • 83

1 Answers1

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

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • 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 : https://imgur.com/a/WnHBeSV . thank you for all your help – stats_noob Mar 14 '21 at 07:01
  • 1
    `rmarkdown::render(input = "dashboard.Rmd", output_file = "main.html")` works for me. – Ronak Shah Mar 14 '21 at 07:04
  • 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 – stats_noob Mar 14 '21 at 07:05
  • 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 at line 2, column 1 ... do you know what could be causing this error? thank you for your help – stats_noob Mar 14 '21 at 07:06
  • 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 – stats_noob Mar 14 '21 at 07:09
  • I don't get any such error on my end. Open the RMD file in RStudio and see if there are any additional spaces in the RMD file at the start. Also to get `Knit to FlexDashboard` option you need to open RMD file in RStudio. Your screenshot in the first comment doesn't show that you have RMD file open. – Ronak Shah Mar 14 '21 at 07:16
  • thank you for your reply. I am starting to understand more. I just opened the RMD file in R studio and now I see this option : https://imgur.com/a/HQg48gy . However, when I click the "Knit to FlexDashboard" option, i get the following error: Error in yaml::yaml.load(..., eval.expr = TRUE) : Parser error: did not find expected at line 2, column 1 Calls: ... parse_yaml_front_matter -> yaml_load -> Execution halted .... do you know what could be causing this? Thank you for all your help – stats_noob Mar 14 '21 at 07:21
  • Is it possible that there is an error in the formatting of the "intro" code? I tried removing spaces but this did not fix the problem --- title:"rbokeh iris dataset" author:"Ryan Hafen" output: flexdashboard::flex_dashboard: orientation:columns social:menu source_code:embed --- – stats_noob Mar 14 '21 at 07:36
  • I posted an updated question over here https://stackoverflow.com/questions/66628978/r-dealing-with-yaml-parser-errors can you please take a look at it if you have some time? thank you for all your help – stats_noob Mar 14 '21 at 20:09
  • Yes, it works now. I think there was some problem at the start of the code – stats_noob Mar 15 '21 at 14:03