Hi, I'm attempting the following:
Goal: Implement a dependent sideBarMenu that contains a dropdown list whose list choices depend on the item selection of another static sideBarMenu.
Issue: Menu item selection keeps reverting back to the first menu item.
I think this has to do something with the callbacks running in the background. Or maybe the structure of my code.
ui <- dashboardPage(
dashboardHeader(title="Some Header"),
dashboardSidebar(
sidebarMenu(id="sbm"
,menuItem("Menu",tabName="m_1"
,menuSubItem("Menu Item 1", tabName="mi_1")
,menuSubItem("Menu Item 2", tabName="mi_2")
,menuSubItem("Menu Item 3", tabName="mi_3")
)
)
,sidebarMenuOutput("dependent_dropdown")
),
dashboardBody(
uiOutput("checkItemValue")
,uiOutput("checkListValue")
)
)## end user function
server <- function(input, output){
react_val <- reactiveValues()
observeEvent(input$sbm,{
react_val$selected_list <- paste0(input$sbm,"_Li_",1:6)
react_val$initial_selection <- paste0(input$sbm,"_Li_",1:6)[1]
})
output$checkItemValue <- renderText({
paste0("Menu Item ",gsub("mi_","",input$sbm)," selected")
})
output$checkListValue <- renderText({
paste0("List Item ",input$dropdown_selection," selected")
})
output$dependent_dropdown <- renderMenu({
sidebarMenu(id="dropdown",
menuItem("Dependent Dropdown"
,selectInput("dropdown_selection"
,paste0("Menu Item ",gsub("mi_","",input$sbm)," list:")
,choices=as.list(react_val$selected_list)
,selected=react_val$initial_selection)
))
})
}## end server function
shinyApp(ui, server)