在R Shine中隐藏TabPanel

时间:2018-06-26 01:08:40

标签: r shiny tabpanel

伙计们。我有一个如何在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")
})

}

与conditionPanel有什么关系吗?还是可能有其他原因?谢谢。

1 个答案:

答案 0 :(得分:2)

提供给hideTab的value是错误的:

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)