Rmarkdown/Shiny可以运行,但无法保存.md和.html输出文件。

6

我正在尝试制作一个带有shiny元素的交互式Rmarkdown文档,并将这个文件上传到运行Shiny Server的服务器。为了使它起作用,我需要来自(本地)Rstudio的输出,以便上传(我认为我需要.md和.html文件)。

以下是一个示例脚本:

---
title: "Untitled"
output: html_document
runtime: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r, echo=FALSE}
inputPanel(
  selectInput("n_breaks", label = "Number of bins:",
              choices = c(10, 20, 35, 50), selected = 20),

  sliderInput("bw_adjust", label = "Bandwidth adjustment:",
              min = 0.2, max = 2, value = 1, step = 0.2)
)

renderPlot({
    hist(faithful$eruptions, probability = TRUE, 
    breaks = as.numeric(input$n_breaks),
    xlab = "Duration (minutes)", main = "Geyser eruption duration")

  dens <- density(faithful$eruptions, adjust = input$bw_adjust)
  lines(dens, col = "blue")
})
```

当我按下Ctrl+Shift+K进行编织时,会输出一个.md文件和一个.html文件(分别写入到/tmp/RtmpazfnvB/.knit.md和/tmp/RtmpazfnvB/file65ab7ab54e0d.html)。同时,一个工作的交互式文档弹出。到目前为止都很好: Rmarkdown Shiny Output 问题是当我尝试保存输出文件时。
  • 如果我点击“在浏览器中打开”,我的浏览器会打开一个空标签页
  • 如果我将浏览器重定向到/tmp/RtmpazfnvB/file65ab7ab54e0d.html,我可以得到一个工作的html,但没有交互元素
  • /tmp/RtmpazfnvB/.knit.md似乎不存在
附加信息:
  • Running Rstudio with sudo didn't change anything,
  • Setting the permissions to /tmp to 777 didn't change anything
  • I am running Ubuntu 17.10, R version 3.4.0, have run update.packages(ask = FALSE)
  • adding html_document: keep_md: true still does not generate an md file
  • The code below gives the error "could not find function "inputPanel":

    rmarkdown::render(input = "markdown_shiny_test1.Rmd", clean=F, runtime = "shiny", output_dir="~")
    

有人知道在这里创建.html/.md文件的问题是什么吗?非常感谢!

1个回答

0

哇!看起来你在一篇帖子中提出了两个或三个问题。让我们一一回答:

1. 为什么knitr不保存.md输出文件?

(尽管它显示"output file: /private/var/folders/7y/b82d7gks5cb4gmzclryh64gc0000gn/T/RtmpIPKroX/filef9322df68e7f/Untitled.knit.md" 或类似的内容)

引用创作者的话

When knitr processes an R Markdown input file, it creates a Markdown (*.md) file that is subsequently transformed into HTML by Pandoc. If you want to keep a copy of the Markdown file after rendering, you can do so using the keep_md option:

--- 
title: "Habits" 
output:   
  html_document:
    keep_md: true
--- 
2. 为什么knitr不保存.html输出?
它明显是保存的,即使在你的示例中,当它没有在外部浏览器中渲染时,它仍然被保存,并且包含了正确的代码(通过打开非交互版本时显示)。
3. 为什么我在浏览器中打开时它不显示?
这是由于你的浏览器问题。可能有很多原因,包括过于严格的广告拦截器。我建议尝试使用另一个浏览器(例如操作系统自带但你从未使用过的),或者关闭所有扩展程序,看看是否能正常工作。
希望对你有所帮助!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接