Search code examples
rr-markdownknitrflexdashboard

How to split flexdashboard pages into multiple rmd files?


I've created a dashboard using rmarkdown flexdashboard with multiple pages. Is it possible to split out each page into its own rmd file since each page is heavy on content and includes multiple plots? In the code below, I'd like to split out each season into its own rmd file but maintain the same tabbed format in flexdashboard.

---
title: "Seasons"
output: flexdashboard::flex_dashboard
---

Summer
=====================================  
    
Column {data-width=600}
-------------------------------------
    
### Chart 1
    
```{r}
```
   
Column {data-width=400}
-------------------------------------
   
### Chart 2

```{r}
```   
 
### Chart 3
    
```{r}
```

Fall {data-orientation=rows}
=====================================     
   
Row {data-height=600}
-------------------------------------

### Chart 1

```{r}
```

Row {data-height=400}
-------------------------------------
   
### Chart 2

```{r}
```   
    
### Chart 3

```{r}
```

Winter {data-orientation=rows}
=====================================     
   
Row {data-height=600}
-------------------------------------

### Chart 1

```{r}
```

Row {data-height=400}
-------------------------------------
   
### Chart 2

```{r}
```   
    
### Chart 3

```{r}
```

Spring {data-orientation=rows}
=====================================     
   
Row {data-height=600}
-------------------------------------

### Chart 1

```{r}
```

Row {data-height=400}
-------------------------------------
   
### Chart 2

```{r}
```   
    
### Chart 3

```{r}
```

Solution

  • Yes, you can create a r-markdown file for each season and then include these in the main r-markdown file using the child chunk-option.

    So the four Rmd file would be,

    season1.Rmd

    Summer
    =====================================  
        
    Column {data-width=600}
    -------------------------------------
        
    ### Chart 1
        
    ```{r}
    ```
       
    Column {data-width=400}
    -------------------------------------
       
    ### Chart 2
    
    ```{r}
    ```   
     
    ### Chart 3
        
    ```{r}
    ```
    
    

    season2.Rmd

    Fall {data-orientation=rows}
    =====================================     
       
    Row {data-height=600}
    -------------------------------------
    
    ### Chart 1
    
    ```{r}
    ```
    
    Row {data-height=400}
    -------------------------------------
       
    ### Chart 2
    
    ```{r}
    ```   
        
    ### Chart 3
    
    ```{r}
    ```
    

    season3.Rmd and season4.Rmd file would be of similar construct.

    Then the main rmarkdown file would look like,

    main_flexdashboard.Rmd

    ---
    title: "Seasons"
    output: flexdashboard::flex_dashboard
    ---
    
    ```{r child = 'season1.Rmd'}
    ```
    
    
    ```{r child = 'season2.Rmd'}
    ```
    
    
    ```{r child = 'season3.Rmd'}
    ```
    
    
    ```{r child = 'season4.Rmd'}
    ```
    
    

    Then simply knitting this main_flexdashboard.Rmd would get you the same result.

    Note that, all these child documents (season1.Rmd, season2.Rmd, etc) need to be in the same folder (directory) as the main_flexdashboard.Rmd file.