在 Shiny 选项卡中使用多个 R Markdown 文件 [英] Use multiple R Markdown files in Shiny tabs
问题描述
我正在构建一个 Shiny 应用程序,我想要多个标签集.到目前为止,我得到的代码给了我:
I am building a Shiny App and I'd like to have multiple tabsets. The code I've got so far gives me that:
shinyUI(navbarPage("OEI Grant",
tabPanel("Part 1 - Organization",
tabsetPanel("1.x",
tabPanel("1.1"),
tabPanel("1.2"),
tabPanel("1.3")
))))
我无法弄清楚的部分是如何为每个选项卡(1.1、1.2 等)获取单独的交互式文档(R markdown .Rmd 文件).
The part I cannot figure out is how to get a separate interactive document (R markdown .Rmd file) for each tab (1.1, 1.2, etc.).
我正在寻找与 includeMarkdown()
函数等效的函数,但要寻找本身包含 Shiny Apps 的 R Markdown 文件.
I am looking for the equivalent of the includeMarkdown()
function but for R Markdown files that themselves contain Shiny Apps.
例如在 1.1 中,我可能想显示以下简单 .Rmd 文件的输出:
For example in 1.1 I may want to display the output from the following simple .Rmd file:
---
runtime: shiny
---
# Data visualization
Example visualization
```{r read-in-data, echo = FALSE, eval=TRUE, message=TRUE}
library(ggplot2)
data(OrchardSprays) # Use this data
head(OrchardSprays)
```
## Histogram
We can also look at this data in an interactive histogram.
```{r histogram, echo = FALSE, eval=TRUE}
shinyAppDir(
"histogram/",
options=list(width="100%", height=450)
)
```
这个 RTutor Shiny App 与我正在尝试做的类似多个选项卡,但从查看它们的代码来看,我认为所有内容都在一个 R markdown 文件中提供,并以某种方式解析为不同的部分.
This RTutor Shiny App is something similar to what I'm trying to do as far as multiple tabs but from looking at their code, I think everything is provided in one R markdown file and somehow parsed into different sections.
R Markdown 文档讨论了 链接多个页面 但我想要内容而不是链接.
R Markdown documentation talks about linking multiple pages but I want the content and not links.
唯一的Tabsets 库中的示例 展示了如何将来自服务器的输出.R 进入不同的标签,但不是单独的 R Markdown 文件.
The only example in the Gallery for Tabsets shows how to put output from server.R into different tabs but not separate R Markdown files.
关于如何做到这一点的任何想法?
Any ideas on how to do this?
推荐答案
作为前面答案中提到的方法的替代方案,您可能想尝试此 repo 中说明的方法 https://github.com/vnijs/shiny-site.这是一个概念证明,您可以在闪亮的应用程序中使用 Knitr 渲染 rmarkdown 文件,而无需应用程序将文件分解成多个部分.它通过使用 Shiny 的 renderUI 功能并在 ShinyServer 环境中评估 rmarkdown 文件来工作.
As an alternative to the approach mentioned in earlier answer you may want to try the approach illustrated in this repo https://github.com/vnijs/shiny-site. This is a proof of concept that you can render rmarkdown files using Knitr within a shiny without app having to break up the file into parts. It works by using Shiny's renderUI functionality and evaluating the rmarkdown file in the shinyServer environment.
这篇关于在 Shiny 选项卡中使用多个 R Markdown 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!