R Shiny modules implementation

shiny

#1

I am trying modules for a shiny app.I am able to get the plots and the table UI. But I have issues when I am trying to implement the dropdown UI. Below is the code which I am using.How could I add multiple dropdowns using modules which would display on across all tabs. Thank you.

UI.r


library(shiny)
library(shinydashboard)
library(dashboardthemes)
library(plotly)
source("module.R")
## ui.R ##
sidebar <- dashboardSidebar(sidebarMenu(id = "tab",
                                        menuItem("1", tabName = "1"),
                                        menuItem("2", tabName = "2"),
                                        menuItem("3", tabName = "3"),
                                        menuItem("4", tabName = "4")
                                        
))

body <-   ## Body content
  dashboardBody(tabItems(
    tabItem(tabName = "atc_topline",
            fluidRow(dropDownUI(id = "Select")),
            fluidRow(chartTableBoxUI(id = "ATC Topline")),
            fluidRow(TableBoxUI(id = "Topline"))) # render the tabBox inside a fluidRow
   )
   )
# Put them together into a dashboardPage
dashboardPage(
  dashboardHeader(title = " Scorecard"),
  sidebar,
  body
)

Module.r

dropDownUI <- function(id, div_width = "col-xs-12 col-md-8") {
  
  ns <- NS(id)
  ##### Flavor levels
  observeEvent(input$metric, {
         choices <- c(
        "foo",
        "zoo",
        "boo"
      )
    }
    updatePickerInput(session,
                      inputId = "metric",
                      choices = choices)
  })
  observeEvent(input$class, {
    choices <- c(
      "aa",
      "bb",
      "cc"
    )}
  updatePickerInput(session,
                    inputId = "class",
                    choices = choices)
  })}

chartTableBoxUI <- function(id, div_width = "col-xs-12 col-md-8") {
    ns <- NS(id)
    ## div(class = div_width,  Check on how to make it responsive with data tables
   div(tabBox(width = 12, title = id,
             tabPanel(icon("bar-chart"),
                      plotlyOutput(ns("chart") )
             ),
             tabPanel(icon("table"),
                      DT::dataTableOutput(ns("table"))
             )))}
chartTableBox <- function(input, output, session, data) {
  
  module_data <- data

  a <- reactive({ })
  b <-reactive({ })

  ab <- reactive({(inner_join(a()[-c(11), ],b()[-c(11), ]))})
 
  output$chart <- renderPlotly({
    plot_ly(ab(), x = ~Month_considered, y = ~pct, type = 'scatter',mode = 'marker',fill = 'tozeroy',line = list(color = 'rgb(205, 12, 24)', width = 4))
  })
  
  output$table <- renderDataTable({
    DT::datatable(ab())
  })
}```