I made a few changes. Mainly, as suggested above, I changed the updateSelectInput inside of the observeEvent call into a selectInput in a renderUI call with the logic for what the choices should be in it. I also added a Sys.sleep(0.2) call because an error message was appearing if the renderUI call was rendering to quickly. This app appears, to me, to do what you want.
As a side note, I commented out the second module because it was not relevant to this problem and I do not have access to the csv that you are loading.
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(
width = 3,
# selectInput(
# inputId = ns("selected_product"),
# label = h4("Product Family"),
# choices <- c("22","33","44"),
# width = "100%"
# )
uiOutput(ns("selected_product_ui"))
))
}
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_Topline"))) # render the tabBox inside a fluidRow
)))
# Put them together into a dashboardPage
ui <- dashboardPage(
dashboardHeader(title = "Loyalty Monthly Scorecard"),
sidebar,
body
)
server = {
shinyServer(function(input, output, session) {
# MyData <- read.csv(file="ldb_data.csv", header=TRUE, sep=",")
# callModule(chartTableBox, id = "ATC_Topline", data = MyData)
callModule(dropDown, id = "dropdown")
})
}
shinyApp(ui = ui, server = server)