我创建了一个包含一些闪亮内容的markdown文件。当我运行当前的块代码时,应用程序工作得很好。但是当我尝试编织代码块时,会出现以下错误:
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输出。
答案 0 :(得分: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.