Hi!
I have an app with nested shiny modules like below. I am unable to get the accordion panels to open/close when calling bslib::accordion_panel_close/open()
from within the inner modules server:
# Libs ----
library(shiny)
library(bslib)
# tests_nav_panel_UI ----
tests_nav_panel_UI <- function(id) {
ns <- NS(id)
page_fluid(
bslib::accordion(
id = ns("Tests_Panel"),
multiple = TRUE,
open = c("Search Tests"),
bslib::accordion_panel(
title = "Search Tests",
tests_search_form_UI(id = ns('tests_search_form'))
),
bslib::accordion_panel(
title = "Tests"
)
)
)
}
# tests_nav_panel_Server ----
tests_nav_panel_Server <- function(id) {
moduleServer(id, function(input, output, session) {
tests_search_form_Server(id = 'tests_search_form', users_panel_id = session$ns("Tests_Panel"), panel_session = session)
})
}
# tests_search_form_UI ----
tests_search_form_UI <- function(id, search_button = "visible") {
ns <- NS(id)
actionButton(
inputId = ns("Search_Tests"),
label = "Search",
class = c("btn-success", search_button)
)
}
# tests_search_form_Server ----
tests_search_form_Server <- function(id, users_panel_id, panel_session) {
moduleServer(id, function(input, output, session) {
observeEvent(input$Search_Tests, {
print(users_panel_id)
print(session$ns("test_id"))
bslib::accordion_panel_close(id = users_panel_id, values = "Search Tests", session = session)
bslib::accordion_panel_open(id = users_panel_id, values = "Tests", session = session)
})
})
}
# ui ----
ui <- page_fluid(
tests_nav_panel_UI(id = "tests_page")
)
# server ----
server <- function(input, output, session) {
tests_nav_panel_Server(id = "tests_page")
}
# Run app ----
shinyApp(ui, server)
The expected effect is that when the input$Search_Test
button in the inner module is clicked, the outer module's Search Tests
accordion closes and the Tests
accordion opens.
Thanks in advance