R: Dealing with “yaml” Parser Errors

I am working with the R programming language. I am trying to replicate the interactive "dashboard" from this website here: https://beta.rstudioconnect.com/jjallaire/htmlwidgets-rbokeh-iris/htmlwidgets-rbokeh-iris.html

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

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

(https://i.stack.imgur.com/zfW82.png)

Then, I deleted all the text in the window that popped up. I copied the R code (word for word) from the website 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. Following the advice from an answer on another stackoverflow question (R: Converting "rmarkdown" to "html" files), I open the "RMD" file in R studio: ("file" -> "open file" -> "dashboard.rmd")

Then, I clicked on "knit" -> "knit to flex_dashboard" :

(https://i.stack.imgur.com/Er1Uo.png)

However, this produces the following error:

Error in yaml::yaml.load(..., eval.expr = TRUE) : 
  Parser error: did not find expected <document start> at line 2, column 1
Calls: <Anonymous> ... parse_yaml_front_matter -> yaml_load -> <Anonymous>
Execution halted

Can someone please tell me what I am doing wrong and how I can fix this error? I am trying to produce the same dashboard as from the original website . What is this YAML error? What exactly is not being "parsed" at line 2, column 1? Is it a problem with the "title" and "author" information from the start of the code? Are there errors in the original code, or am I doing something procedurally wrong?

Thanks

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252    LC_MONETARY=English_Canada.1252
[4] LC_NUMERIC=C                    LC_TIME=English_Canada.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rmarkdown_2.7       knitr_1.31          flexdashboard_0.5.2

loaded via a namespace (and not attached):
 [1] compiler_4.0.3    htmltools_0.5.1.1 tools_4.0.3       yaml_2.2.1        tinytex_0.30      jsonlite_1.7.2   
 [7] digest_0.6.27     xfun_0.21         rlang_0.4.10      evaluate_0.14  

The formatting is not appearing correctly - here is the same question posted on stackoverflow: https://stackoverflow.com/questions/66628978/r-dealing-with-yaml-parser-errors

The only yaml is at the top of the Rmd file

---
title: "rbokeh iris dataset"
author: "Ryan Hafen"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    social: menu
    source_code: embed
---

It worked for me (no tabs, no trailing spaces)

![iris|617x500](upload://qcOVxcTMhIWiA7GiPGZWWflpK7.png) 

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.