如何使用`bslib::accordion_panel_update()`来更新面板的标题

问题描述 投票:0回答:1

我想动态更改手风琴面板的标题。我认为

bslib::accordion_panel_update
是执行此操作的正确函数,但我无法让它工作。

这是一个最小的例子:

ui <- bslib::page_sidebar(
    sidebar=bslib::sidebar(
        open="always",
        position="right",
        shiny::selectInput(
            inputId="acc_title", 
            label="Accordion Panel's title",
            choices=c("Title 1", "Title 2"),
            selected="Title 1",
            multiple=FALSE
        )
    ),
    bslib::card(
        "Some content",
        bslib::card_footer(
            bslib::accordion(
                id="acc",
                open=FALSE,
                multiple=FALSE,
                bslib::accordion_panel(
                    id="acc_panel", # also tried "value=" here
                    "Title 1",
                    "Accordion's content."
                )
            )
        )
    )
)
server = function(input, output, session) {
    shiny::observeEvent(input$acc_title, {
        bslib::accordion_panel_update( # <-- crucial part
            id="acc", 
            target="acc_panel",
            title = input$acc_title
        )
    })
}
shiny::runApp(shinyApp(ui, server))

也许我混淆了

accordion_panel_update
的一些论点。我怎样才能让它工作?

r shiny bslib
1个回答
0
投票

我找到了问题(以及解决方案)。

bslib::accordion_panel(
    value="acc_panel", # not "id"
    "Title 1",
    "Accordion's content."
)

在我的原始代码中,我正在使用闪亮的模块并拥有

value=ns("acc_panel")
。这是行不通的。只有
accordion
需要命名空间函数。我想这就是为什么该参数被称为
value
而不是
id

© www.soinside.com 2019 - 2024. All rights reserved.