Using value from one shiny module to another shiny module

shiny
shiny-modules

#1

I am trying to use a value from one shiny module and pass it to a second shiny module to print it. So when user select orange from first dropdown it show print you have selected orange. But as of now it prints you have selected ATC which is nothing but the id I am passing . Below is the code I am using.Thank you.

library(shiny)
library(shinydashboard)
library(shinyWidgets)

dropDownUI <- function(id, div_width = "col-xs-12 col-md-8") {

  ns <- NS(id)

  div(column(3, uiOutput(ns("class_level"))),
      column(3,uiOutput(ns("selected_product_ui"))
      ))
}

chartTableBoxUI <- function(id, div_width = "col-xs-12 col-md-8") {
  ns <- NS(id)

  div(tabBox(width = 12, title = id,
             tabPanel(icon("bar-chart"),
                      textOutput(ns("selected_var")))
   )
  )
}

chartTableBox <- function(input, output, session, data) {

  output$selected_var <- renderText({
    ns <- session$ns
    paste("You have selected",ns(input$selected_class))
  })
}

dropDown <- function(input, output, session) {

  ns <- session$ns

  output$class_level <- renderUI({
    selectInput(
      ns("selected_class"),
      label = h4("Classification Level"),
      choices = list(
        "apple " = "apple",
        "orange " = "orange"),
      selected = "orange"
    )})

  output$selected_product_ui <- renderUI({
    req(input$selected_class)
    Sys.sleep(0.2)
    ns <- session$ns

    if (input$selected_class == "apple") {
      my_choices <- c("foo","zoo","boo")
    } else if (input$selected_class == "orange") {
      my_choices <- c("22","33","44")
    } else {
      my_choices <- c("aa","bb","cc")
    }

    selectInput(inputId = ns("selected_product"),
                label = h4("Product Family"),
                choices = my_choices)
  })

}

sidebar <- dashboardSidebar(sidebarMenu(
  menuItem("aaa",tabName = "aaa"),
  menuItem("bbb", tabName = "bbb"),
  menuItem("ccc", tabName = "ccc")
))

body <-   ## Body content
  dashboardBody(tabItems(
    tabItem(tabName = "aaa",
            fluidRow(dropDownUI(id = "dropdown"),
                     fluidRow(chartTableBoxUI(id = "ATC"))
            )
    )))
# Put them together into a dashboardPage
ui <-   dashboardPage(
  dashboardHeader(title = "Loyalty Monthly Scorecard"),
  sidebar,
  body
)

server = {
  shinyServer(function(input, output, session) {
    callModule(dropDown, id = "dropdown")
    callModule(chartTableBox, id = "ATC", data = MyData)

  })
}

shinyApp(ui = ui, server = server)