浏览器刷新后,交互式rmarkdown文档无法正确显示

时间:2014-07-24 09:42:37

标签: r shiny r-markdown

我正在运行以下交互式rmarkdown文档:

### 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')
  })
```

保存为minimal.Rmd,我通过运行

运行它
rmarkdown::run("minimal.Rmd")
R控制台上的

。运行后,文档在浏览器上正确显示:

App displayed correctly

刷新浏览器后,文档如下所示:

App displayed incorrectly

(我在chrome和safari上试过这个)

我注意到当我在保存.Rmd文件后立即运行rmarkdown :: run时,我在R控制台上得到类似knitr的输出,文档显示正确;当运行rmarkdown :: run而不重新保存文件时,不会在控制台上产生类似knitr的输出,并且文档显示不正确。这可能与rmarkdown :: run缓存有关。我得到的类似knitr的输出是:

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

我的会话信息是:

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

1 个答案:

答案 0 :(得分:6)

添加:

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

到文档的顶部修复了问题。 Fereshteh Karimeddini在Shiny用户Google小组中发表Answered