---
title: "Insert modules in flexdashboard"
output:
flexdashboard::flex_dashboard
runtime: shiny
---
```{r}
# include the worldPhones module
worldPhonesUI <- function(id) {
ns <- NS(id)
fillCol(height = 400, flex = c(NA, 1),
inputPanel(
selectInput(ns("region"), "Region:", choices = colnames(WorldPhones))
),
plotOutput(ns("phonePlot"), height = "100%")
)
}
# Server function
worldPhones <- function(input, output, session) {
output$phonePlot <- renderPlot({
barplot(WorldPhones[,input$region]*1000,
ylab = "Number of Telephones", xlab = "Year")
})
}
```
Sidebar {.sidebar}
------------------
Click the insert button below to add worldPhone module to the right. You can add as many modules as you want
```{r}
actionButton("insertModule", "Insert Module")
```
MainPage
-----------------
### World Phones modules {.no-title}
```{r}
h2("Module examples")
observeEvent(input$insertModule, {
id = input$insertModule
phoneid <- paste0("phones", id)
callModule(worldPhones, phoneid)
insertUI(selector = "h2",
where = "afterEnd",
ui = tagList(
h4(paste0("Module number ", id)),
worldPhonesUI(phoneid))
)
})
```.