Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use multiple R Markdown files in Shiny tabs

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")
                       ))))

Current Layout

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.).

I am looking for the equivalent of the includeMarkdown() function but for R Markdown files that themselves contain Shiny Apps.

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)
  )
```

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 documentation talks about linking multiple pages but I want the content and not links.

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?

like image 523
Stefan Avey Avatar asked Dec 24 '22 22:12

Stefan Avey


1 Answers

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.

like image 198
Vincent Avatar answered Dec 27 '22 10:12

Vincent