I have a shiny app with a mainPanel and a sidebarPanel inside a tabPanel in a navbarPage. I need an option to hide the sidebarPanel similar to this: Hide sidebar in default in shinydashboard and https://github.com/daattali/shinyjs/issues/43.
An actionButton should control if the sidebarPanel is shown or collapsed.
This is the code:
library(shiny)
library(shinyjs)
ui <- fluidPage(
navbarPage("",
tabPanel("tab",
sidebarPanel(
useShinyjs()
),
mainPanel(actionButton("showSidebar", "Show sidebar"),
actionButton("hideSidebar", "Hide sidebar")
)
)
)
)
server <-function(input, output, session) {
observeEvent(input$showSidebar, {
shinyjs::removeClass(selector = "body", class = "sidebarPanel-collapse")
})
observeEvent(input$hideSidebar, {
shinyjs::addClass(selector = "body", class = "sidebarPanel-collapse")
})
}
shinyApp(ui, server)
Hope somebody can help :)