Search code examples
rflexdashboard

Dynamicly increasing amount of tabs and pages in flexdashboards


So I just started using flexdashboard to visualize my results and i have a critical question. In my procedure i have a dataset with 10 columns which updates everyday. In the end of the day I am reporting only the columns that are in a way significant.

The thing is that in some days I need to report 2 columns, and in some other 10 columns. So i was thinking to automate this in flexdashboard.

To define a new row with tabs we do (e.g for 2 tabs)

Row {.tabset .tabset-fade}
-----------------------------------------------------------------------

### Chart A
```{r}
one <- my_visualization function(data[,1])
```

### Chart B
```{r}
two <-  my_visualization function(data[,2])
```

Which creates a row with two tabs.

My question is: Is there any way to produce as many tabs as say a variable c indicates? (say c=4, i would want 4 tabs!)

Sorry if this has been answered before! Thanks in advance!


Solution

  • The trick is to use the cat function. below is an outline. essentially it is a for loop with the day's plots with the inclusion of the two 'cat' calls. This approach allows for variable tab numbers to be generated. By adding {.tabset} this will make the display neater when there are many plots, instead of generating long documents. The '\n' are critical to create a new line, otherwise the hashtags don't work.

    Hopefully you found this already. Just adding this for others.

        # todays results (.tabset)
        
        ```{r}
        
        rlist <- c(columns to plot)
    
        for (r in rlist) {
          
          
          cat(paste0('## ', r, '\n'))
          
          
         # insert your plot
          
          cat'\n\n')
          
        }
        
        ````