Shiny: Default Rmd code + Error in yaml - Parser error: did not find expected <document start> at line 2, column 1

Created on 27 Mar 2017  路  16Comments  路  Source: rstudio/shiny

Hi,

I am running into an issue that seems related to a bug introduced in one of the more recent updates for shiny (I am currently running the 1.0.0 version).

Execute a very simple R Markdown Shiny document like:

  title: "Something Wrong"
  output: html_document
  runtime: shiny
  ---

  Hello World

This gives me an error message

Error in yaml::yaml.load(string, ...) :
Parser error: did not find expected at line 2, column 1
Calls: ... parse_yaml_front_matter -> yaml_load_utf8 -> -> .Call
Execution halted

Any help is greatly appreciated!

addendum: Issue persists when using the devtools version 1.0.0.9001.

Most helpful comment

See this. Are you sure there is no white space on your YAML header? For that error, the culprit tends to be that somewhere in your YAML you have extra spaces (or not enough spaces) before a key value.

All 16 comments

See this. Are you sure there is no white space on your YAML header? For that error, the culprit tends to be that somewhere in your YAML you have extra spaces (or not enough spaces) before a key value.

Correctly formatted YAML (all OK):
screen shot 2017-03-27 at 2 40 09 pm

Incorrectly formatted YAML (error):
screen shot 2017-03-27 at 2 39 51 pm

Sadly, I am absolutely sure.

I get the very same error when using the default template (New File -> R Markdown ... ).

But thanks!

On a side note:

The issue exists on macOS and Linux.

Strangely enough, the same files seem to work when accessed via Shiny server (i.e. when they are hosted on the Shiny server).

This is likely an issue with rmarkdown, not Shiny itself.

Can you attach the files that you are using to do this? It's possible there's a strange invisible character in there. Also, can you run the following in a clean R session and paste the output?

library(shiny)
library(rmarkdown)
devtools::session_info()
Session info ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.2 (2016-10-31)
 system   x86_64, darwin13.4.0        
 ui       RStudio (1.0.136)           
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       Europe/Zurich               
 date     2017-03-27                  

Packages -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 package    * version    date       source                        
 backports    1.0.5      2017-01-18 CRAN (R 3.3.2)                
 devtools     1.12.0     2016-06-24 CRAN (R 3.3.0)                
 digest       0.6.12     2017-01-27 cran (@0.6.12)                
 evaluate     0.10       2016-10-11 cran (@0.10)                  
 htmltools    0.3.5      2016-03-21 cran (@0.3.5)                 
 httpuv       1.3.3      2015-08-04 CRAN (R 3.3.0)                
 knitr        1.15.1     2016-11-22 CRAN (R 3.3.2)                
 magrittr     1.5        2014-11-22 CRAN (R 3.3.0)                
 memoise      1.0.0      2016-01-29 CRAN (R 3.3.0)                
 mime         0.5        2016-07-07 CRAN (R 3.3.0)                
 R6           2.2.0      2016-10-05 CRAN (R 3.3.0)                
 Rcpp         0.12.10    2017-03-19 CRAN (R 3.3.2)                
 rmarkdown  * 1.4        2017-03-24 CRAN (R 3.3.2)                
 rprojroot    1.2        2017-01-16 CRAN (R 3.3.1)                
 rstudioapi   0.6        2016-06-27 CRAN (R 3.3.0)                
 shiny      * 1.0.0.9001 2017-03-27 Github (rstudio/shiny@f33f712)
 stringi      1.1.3      2017-03-21 CRAN (R 3.3.2)                
 stringr      1.2.0      2017-02-18 CRAN (R 3.3.2)                
 withr        1.0.2      2016-06-20 CRAN (R 3.3.0)                
 xtable       1.8-2      2016-02-05 cran (@1.8-2)  

Thanks for looking into this.

As said, I/ you can load a default R Markdown file with a Shiny runtime and I get this error.

Above example is just simplified, but the default example of RStudio also generates the same error.

Thanks!

I'm not able to reproduce this error with the template document.

> devtools::session_info()
Session info ---------------------------------------------------------------
 setting  value                       
 version  R version 3.3.2 (2016-10-31)
 system   x86_64, darwin13.4.0        
 ui       RStudio (1.1.122)           
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/Chicago             
 date     2017-03-27                  

Packages -------------------------------------------------------------------
 package   * version    date       source                        
 backports   1.0.5      2017-01-18 CRAN (R 3.3.2)                
 devtools    1.12.0     2016-06-24 CRAN (R 3.3.0)                
 digest      0.6.12     2017-01-27 cran (@0.6.12)                
 evaluate    0.10       2016-10-11 CRAN (R 3.3.0)                
 htmltools   0.3.5      2016-03-21 CRAN (R 3.3.0)                
 httpuv      1.3.3      2015-08-04 CRAN (R 3.3.0)                
 knitr       1.15.1     2016-11-22 CRAN (R 3.3.2)                
 magrittr    1.5        2014-11-22 CRAN (R 3.3.0)                
 memoise     1.0.0      2016-01-29 CRAN (R 3.3.0)                
 mime        0.5        2016-07-07 CRAN (R 3.3.0)                
 R6          2.2.0      2016-10-05 CRAN (R 3.3.0)                
 Rcpp        0.12.10    2017-03-19 CRAN (R 3.3.2)                
 rmarkdown * 1.4        2017-03-24 CRAN (R 3.3.2)                
 rprojroot   1.2        2017-01-16 CRAN (R 3.3.2)                
 shiny     * 1.0.0.9001 2017-03-24 Github (rstudio/shiny@00ab868)
 stringi     1.1.3      2017-03-21 CRAN (R 3.3.2)                
 stringr     1.2.0      2017-02-18 CRAN (R 3.3.2)                
 withr       1.0.2      2016-06-20 CRAN (R 3.3.0)                
 xtable      1.8-2      2016-02-05 CRAN (R 3.3.0)                
 yaml        2.1.14     2016-11-12 CRAN (R 3.3.2)                

I've been able to further isolate the issue:

It seems like it is solely related to one particular project folder I have. With all my projects I use GitHub repositories. In all other repositories, the R Markdown Shiny report runs fine.

I've checked the Rproj file and again downloaded a fresh copy of the repository. But the error still exists.

Does anybody have a good idea what is causing this?

I think this is an issue with rmarkdown, not shiny, so it would be best to file an issue there.
https://github.com/rstudio/rmarkdown/issues

I've identified the reason why this happens. Filed a bug report here: https://github.com/rstudio/rmarkdown/issues/1005

@S-UP find a fix yet?

I had exactly the same problem.It looked really steange
In two different directories I did exactly the same to create a new .Rmd with shiny file from template:
File->New File ->R Markdown... ----> X Shiny.

Then in one directory it would run ok. In the other it produced this error:

Error in yaml::yaml.load(string, ...) :
Scanner error: mapping values are not allowed in this context at line 4, column 10
Calls: ... parse_yaml_front_matter -> yaml_load_utf8 -> -> .Call
Execution halted

Then I found this post and THIS EXPLANATION: _In your case, all Rmd files have to be scanned to determine the default_file._

So I moved all my other Rmd files away from this directory, and then it worked fine!

Error in yaml::yaml.load(..., eval.expr = TRUE) :
Parser error: while parsing a block mapping at line 1, column 1 did not find expected key at line 2, column 25
Calls: ... parse_yaml_front_matter -> yaml_load ->
Execution halted
I get the same error.

I'll add my two cents to this. After reading several issues and looking at several posts, I finally fixed an issue like this by providing a space between ---. It seems the function that parses the yaml requires this space. This would appear counterintuitive to this.

I ran into the same issue and now have it fixed.

The solution that worked was using a .yml formatting helper site.

Like this one.

Found there was as space where there shouldn't be.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ClementeProduzente picture ClementeProduzente  路  32Comments

ktanizar picture ktanizar  路  46Comments

DarioS picture DarioS  路  12Comments

dmpe picture dmpe  路  13Comments

Silentdevildoll picture Silentdevildoll  路  14Comments