首页 > 解决方案 > 在R闪亮中隐藏标签面板

问题描述

伙计们。我有一个关于如何在 R Shiny 中隐藏 tabpanel 的问题。我在这里阅读了参考资料。 https://shiny.rstudio.com/reference/shiny/1.0.5/showTab.html

然后,我根据这个参考修改了我的代码,但是没有用。这是我的代码的一部分:

  ui <- fluidPage(

sidebarLayout(
  sidebarPanel(
    conditionalPanel(
    condition = "input.tabselected == 1",
    ....
   actionButton("hideTab","Hide Tab"),
   actionButton("showTab","Show Tab")
  ),

  mainPanel(
      tabsetPanel(type = "tabs",
                tabPanel(title = "D", 
                         value=1),
                tabPanel(title = "S", 
                         value=3),
                tabPanel(title = "Y", 
                         value=2),
                id = "tabselected")
  )

...

      server <- function(input, output) {
  hideTab(inputId = "tabselected", target = "Y")
})

}

与条件面板有什么关系吗?还是可能有其他原因?谢谢你。

标签: rshinytabpanel

解决方案


value提供给 hideTab 是错误的:

ui <- fluidPage(

  sidebarLayout(
    sidebarPanel(
      conditionalPanel(
        condition = "input.tabselected == 1",
        actionButton("hideTab","Hide Tab"),
        actionButton("showTab","Show Tab")
      )
    ),
      mainPanel(
        tabsetPanel(type = "tabs",
                    tabPanel(title = "D", 
                             value=1),
                    tabPanel(title = "S", 
                             value=3),
                    tabPanel(title = "Y", 
                             value=2),
                    id = "tabselected")
      )
  )
)

server <- function(input, output) {
  observeEvent(input$hideTab, {
    hideTab(inputId = "tabselected", target = "2")
  })
}

shinyApp(ui = ui, server = server)

推荐阅读