Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interactive rmarkdown document not displaying correctly after browser refresh

I'm running the following interactive rmarkdown document:

### Example of shiny app

```{r, echo = FALSE, eval = TRUE}
  numericInput("rows", "How many cars?", 5)

renderTable({
    head(cars, input$rows)
})
```

### Another example

```{r, echo = FALSE}
  sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)

  renderPlot({
    x <- faithful[, 2]  # Old Faithful Geyser data
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })
```

saved as minimal.Rmd, I run it by running

rmarkdown::run("minimal.Rmd")

on the R console. After running that, the doc displays correctly on the browser:

App displayed correctly

After refreshing the browser, the document looks like this:

App displayed incorrectly

(I've tried this on chrome and safari)

I've noticed that when I run rmarkdown::run immediately after saving the .Rmd file I get knitr-like output on the R console, and the document displays correctly; when running rmarkdown::run without re-saving the file doesn't produce the knitr-like output on the console and the document displays incorrectly. This might have to do with rmarkdown::run caching stuff. The knitr-like output I get is:

Listening on http://127.0.0.1:6381


processing file: minimal.Rmd
  |................                                                 |  25%
  |................................                                 |  50%
  |.................................................                |  75%
  |.................................................................| 100%
label: unnamed-chunk-2 (with options) 
List of 1
 $ echo: logi FALSE


output file: /var/folders/15/q9z0km897fs93f_z1slpf09h0000gp/T//Rtmpt7kc98/minimal.knit.md

/usr/local/bin/pandoc /var/folders/15/q9z0km897fs93f_z1slpf09h0000gp/T//Rtmpt7kc98/minimal.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output /var/folders/15/q9z0km897fs93f_z1slpf09h0000gp/T/rmarkdown/rmd_b468d17c42847143a4499f693d7a0f45.html --smart --email-obfuscation none --standalone --section-divs --template /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rmarkdown/rmd/h/default.html --variable theme:bootstrap --mathjax --variable mathjax-url:https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML --no-highlight --variable highlightjs=rmd_b468d17c42847143a4499f693d7a0f45_files/highlight 

Output created: /var/folders/15/q9z0km897fs93f_z1slpf09h0000gp/T/rmarkdown/rmd_b468d17c42847143a4499f693d7a0f45.html
Warning in addResourcePath(prefix, dependency$src$file) :
  Overriding existing prefix rmarkdown-performance-0.1 => /private/var/folders/15/q9z0km897fs93f_z1slpf09h0000gp/T/rmarkdown/rmd_54619711603ff951c709d43a6cda206b_files

My session info is:

sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

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

other attached packages:
[1] shiny_0.10.0     rmarkdown_0.2.46

loaded via a namespace (and not attached):
 [1] bitops_1.0-6    caTools_1.17    digest_0.6.4    evaluate_0.5.5  formatR_0.10    htmltools_0.2.4
 [7] httpuv_1.3.0    knitr_1.6       Rcpp_0.11.2     RJSONIO_1.2-0.2 stringr_0.6.2   tools_3.1.0    
[13] xtable_1.7-3
like image 534
ArturoSaCo Avatar asked Jul 24 '14 09:07

ArturoSaCo


People also ask

Why is my R Markdown file not knitting?

No Knit HTML button This means that RStudio doesn't understand your document is supposed to be an RMarkdown document, often because your file extension is . txt . To fix this, go to the Files tab (lower right corner, same pane as Plots and Help) and select the checkbox next to your document's name.

How do I show output in R Markdown?

If you prefer to use the console by default for all your R Markdown documents (restoring the behavior in previous versions of RStudio), you can make Chunk Output in Console the default: Tools -> Options -> R Markdown -> Show output inline for all R Markdown documents .

What is the difference between Markdown and R Markdown?

R Markdown (markup language)R Markdown files are plain text files that typically have the file extension . Rmd . They are written using an extension of markdown syntax that enables R code to be embedded in them in a way which can later be executed.

How do I view an RMD file?

Rmd file. To open a new file, click File > New File > R Markdown in the RStudio menu bar. A window will pop up that helps you build the YAML frontmatter for the . Rmd file.


1 Answers

Adding:

--- runtime: shiny output: html_document ---

to the top of the document fixes the problem. Answered by Fereshteh Karimeddini on the Shiny users Google group.

like image 90
ArturoSaCo Avatar answered Nov 17 '22 00:11

ArturoSaCo