伙计们。我有一个关于如何在 R闪亮中隐藏 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")
)
Run Code Online (Sandbox Code Playgroud)
...
server <- function(input, output) {
hideTab(inputId = "tabselected", target = "Y")
})
Run Code Online (Sandbox Code Playgroud)
}
和conditionPanel有什么关系吗?或者可能还有其他原因?谢谢。
提供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)
Run Code Online (Sandbox Code Playgroud)