Shiny Modules (shinydashboard)

I've recently become very interested in utilizing ShinyModules to scale shiny apps. I've walked through examples, and have built out a few apps using the logic. However, the one thing that I have not seen, is a good example on how to modularize a shinydashboard.

Below is a typical use case:

  • Menu Items
  • Sub Menu Items
  • Conditional Inputs (based on menu items/submenu items)
  • Reactive Data that feeds multiple visuals/models within the same page

The Module workflow seems to be ideal for this (repeatable process, repeats "menu_id" 3 times), but I'm unsure of how to best implement it. Has anyone successfully implemented shinyModules within a similar context?

library(shiny)
library(shinydashboard)
library(tidyverse)

shinyApp(
  ui = dashboardPage(
    dashboardHeader(),
    dashboardSidebar(
      sidebarMenu(
        id = "side_bar",
        menuItem("name of item", tabName = "menu_id"),
        conditionalPanel(
          condition = "input.side_bar == 'menu_id'",
          selectInput("select_input",
            "select",
            choices = letters,
            multiple = T,
            selected = letters[1]
          )
        )
      )
    ),
    dashboardBody(
      tabItems(
        tabItem(
          tabName = "menu_id",
          fluidRow(plotOutput("this_plot"))
        )
      )
    )
  ),
  server = function(input, output) {
    reac_dat <- reactive({
      tibble(
        group = sample(letters, 600, T),
        x = rpois(600, 100),
        y = sample(1:100, 600, T)
      ) %>%
        filter(group %in% input$select_input)
    })


    output$this_plot <- renderPlot({
      reac_dat() %>%
        ggplot(aes(x, y, color = group)) +
        geom_point()
    })
  }
)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.