【问题标题】:Update Controlbar in bs4dash version 2.00 Shiny更新 bs4dash 版本 2.00 Shiny 中的控制栏
【发布时间】:2021-04-23 02:40:41
【问题描述】:

我已移至新的 bs4dash,但在更新控制栏时遇到了一些问题。 对于我侧边栏上的每个不同选项卡,我想要一个相应的控制栏。例如,如果侧边栏选项卡是“主页”,我希望控制栏由多个 selectizeInputs 组成。但是,如果侧边栏选项卡是“新闻”,我希望控制栏有不同的文本输出。

这是我正在使用的一些代码

##UI
  controlbar = dashboardControlbar(
    id = "controlbar",
    collapsed = T
  
    )

##Server 

observeEvent(input$current_tab,{
if(input$current_tab == "home"){
updateControlbar(id = "controlbar", session = session,
selectizeInput("one", "one", choices = c(1,2,3)
), 
selectizeIntput("two", "two", choices = c(1,2,3)
} else if(input$current_tab == "News"){
updateControlbar(id = "controlbar", session = session,
textInput("news1"),
textInput("news2")
}
})

我也尝试了许多其他组合,但似乎没有任何效果。 谢谢你的帮助

【问题讨论】:

  • 您能发布完整的可重现代码吗?这将为那些想帮助你的人提供帮助。

标签: r shiny bs4dash


【解决方案1】:

您可以将条件面板与反应式函数结合使用。这段代码 sn -p 显示了一个非常琐碎的案例。

library(shiny)
library(bs4Dash)

shinyApp(
    ui = dashboardPage(
        header = dashboardHeader(),
        sidebar = dashboardSidebar(uiOutput("sidebar")),
        body = dashboardBody(),
        controlbar = dashboardControlbar(uiOutput("controlbar"))
    ),
    server = function(input, output, session) {
        output$sidebar <- renderMenu({
            sidebarMenu(id = "main_menu",
                menuItem(text = "First page", tabName = "tab1"),
                menuItem(text = "Second page", tabName = "tab2")
            )
        })
        output$show_tab1 <- reactive({
            !is.null(input$main_menu) && input$main_menu == "tab1"
        })
        output$show_tab2 <- reactive({
            !is.null(input$main_menu) && input$main_menu == "tab2"
        })
        outputOptions(output, "show_tab1", suspendWhenHidden = FALSE)
        outputOptions(output, "show_tab2", suspendWhenHidden = FALSE)
        output$controlbar <- renderUI({
            div(
                conditionalPanel(
                    condition = "output.show_tab1",
                    p("Widgets for the first page")
                ),
                conditionalPanel(
                    condition = "output.show_tab2",
                    p("Widgets for the second page")
                )
            )
        })
    }
)

【讨论】:

    猜你喜欢
    • 2022-09-26
    • 2021-06-28
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 2022-01-17
    • 2019-04-07
    相关资源
    最近更新 更多