【问题标题】:Knitting markdown file having shiny content具有闪亮内容的针织降价文件
【发布时间】:2018-11-27 04:19:53
【问题描述】:

我创建了一个包含一些闪亮内容的降价文件。当我运行当前的块代码时,应用程序工作得很好。但是当我尝试编织代码块时,它会出现以下错误:

Shiny applications not supported in static R Markdown documents.

反正我可以编织这段代码吗?

在我阅读的某些网站上,也可以这样做

```{r, echo=FALSE}
library(shiny)
shinyAppDir(
  system.file("examples/06_tabsets", package = "shiny"),
  options = list(
    width = "100%", height = 550
  )
)
```

但是当我编织这个时,同样的事情又发生了。有什么方法可以从闪亮的应用程序中获取 html 输出。

【问题讨论】:

  • runtime: shiny 添加到 YAML 中?

标签: r shiny knitr


【解决方案1】:

要添加闪亮的交互,请将runtime: shiny 添加到 YAML。

请参阅link,了解如何在文档中嵌入闪亮的应用程序。

参见在 Rstudio (file > new file > R markdown > Shiny document) 中创建新 Markdown 文件时给出的标准示例:

--- 
title: "Untitled" 
author: "author" 
date: "July 24, 2018" 
output: html_document runtime: shiny
---

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

This R Markdown document is made interactive using Shiny. Unlike the more traditional workflow of creating static reports, you can now create documents that allow your readers to change the assumptions underlying your analysis and see the results immediately. 

To learn more, see [Interactive Documents](http://rmarkdown.rstudio.com/authoring_shiny.html).

## Inputs and Outputs


    ```{r eruptions, 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")
})
```

## Embedded Application

Its also possible to embed an entire Shiny application within an R Markdown document using the `shinyAppDir` function. This example embeds a Shiny application located in another directory:

```{r tabsets, echo=FALSE} 
shinyAppDir(
system.file("examples/06_tabsets", package = "shiny"),   
options = list(width = "100%", height = 550   ) 
) 
```

Note the use of the `height` parameter to determine how much vertical space the embedded application should occupy.

You can also use the `shinyApp` function to define an application inline rather then in an external directory.

In all of R code chunks above the `echo = FALSE` attribute is used. This is to prevent the R code within the chunk from rendering in the document alongside the Shiny components.

【讨论】:

  • 如何在没有 Rstudio 的情况下运行/渲染它? OP 要求:从闪亮的应用程序中获取 html 输出(他想要一个 html 文件)。
  • 啊,对不起,我可能误解了这个问题。我认为,在没有 R 在后台运行的情况下运行闪亮的应用程序是不可能的。没有 Rstudio 是可能的,参见例如 stackoverflow.com/questions/15884975/…
  • 顺便说一句:有几种方法可以托管和部署包含闪亮应用程序的闪亮应用程序或降价文档 (shiny.rstudio.com/deploy)。您可以在 Markdown 文档中的其他位置插入指向该应用程序的链接
  • @JdP 我第一次被困在这里是当我试图运行 readline() 函数然后编织它时。那是我第一次遇到这个错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-25
  • 2017-02-25
  • 1970-01-01
  • 2017-11-30
  • 2018-03-12
  • 2022-09-27
相关资源
最近更新 更多