【问题标题】:Interactive rmarkdown document not displaying correctly after browser refresh浏览器刷新后交互式 rmarkdown 文档无法正确显示
【发布时间】:2014-09-15 19:20:51
【问题描述】:

我正在运行以下交互式 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 控制台上。运行后,文档在浏览器上正确显示:

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

(我在 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

【问题讨论】:

  • 我可以在 Windows 上重现这个。还没有解决方案。

标签: r shiny r-markdown


【解决方案1】:

添加:

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

到顶部的文档修复了这个问题。 Answered 来自 Shiny users Google 组的 Fereshteh Karimeddini。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-24
    • 2019-01-29
    • 2022-06-12
    • 1970-01-01
    • 2015-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多