I have a shiny app with a sidebarpanel and a main panel with multiple tabs. I want to collapse the sidebarpanel for some tabs and show it for some tabs.
How can I do the same? Thanks.
I have a shiny app with a sidebarpanel and a main panel with multiple tabs. I want to collapse the sidebarpanel for some tabs and show it for some tabs.
How can I do the same? Thanks.
I am not really sure you really need to "hide" or just specify for some tabs a sidebar and for some not (see the ui part). In case you need to hide a sidebar see the (commented) server part.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
navbarPage("",
tabPanel("tab",
div( id ="Sidebar",sidebarPanel(
actionButton("showSidebar", "I am tab sidebar content")
)),
mainPanel(actionButton("showSidebar", "I am tab main content")
)
),
tabPanel("tab2",
div( id ="Sidebar2",sidebarPanel(
actionButton("showSidebar", "I am tab2 sidebar content")
)),
mainPanel(actionButton("showSidebar", "I am tab2 main content")
)
),
tabPanel("tab3",
mainPanel(actionButton("showSidebar", "I dont have a sidebar")
)
)
)
)
server <-function(input, output, session) {
# In case you need to hide them for some reason
# observeEvent(input$tabs == "tab", {
# shinyjs::hide(id = "Sidebar")
# })
}
shinyApp(ui, server)