Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
How to enable toggling between 3 menu items in shiny dashboard sidebar

I would like to make menu items in my shiny dashboard collapsible.

I found the post with similar question that had been answered some time ago:

solution to the problem with 2 div-s

However, the solution works only with 2 div-s. Is it possible to do similar thing with 3 menu items?

Attached reproducible code (posted by Martin Schmelzer)

library(shiny)
library(shinydashboard)

server <- function(input, output) { }
jsc <- '
$(document).ready(function () {
  $(".sidebar-menu").children("li").on("click", function() {
    $("#mult, #single").toggle();
  });
});
'

ui <- dashboardPage(
  dashboardHeader(title = "Dashboard", titleWidth = 290),  
  dashboardSidebar(
    width = 290,
    sidebarMenu(
      menuItem(
        "Multiple Incident Analysis",
        tabName = "dashboard",
        icon = icon("th")),      
      div(id = "mult", splitLayout(cellWidths = c("44%", "31%", "25%"),
                  dateInput("datefrom", "Date From:", format = "mm/dd/yyyy", Sys.Date()-5),
                  textInput("datefrom_hour", "Hour",
                            value = "12:00"),
                  textInput("datefrom_noon","AM/PM", value = "AM")),      
      splitLayout(cellWidths = c("44%", "31%", "25%"),
                  dateInput("dateto", "Date To:", format = "mm/dd/yyyy"),
                  textInput("dateto_hour", "Hour",
                            value = "11:59"),
                  textInput("dateto_noon","AM/PM", value = "PM"))),
      menuItem("Single Analysis", 
               tabName = "widgets", 
               icon = icon("th")),
      div(id = "single", style="display: none;", numericInput("tckt", "Ticket Number : ", 12345,  width = 290)),
      submitButton("Submit", width = "290")
    )),  
  dashboardBody(
    tags$head(tags$script(jsc))
  ))

shinyApp(ui, server)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In shinydashboard, menuItem already does that for as many menu items as you want. Try this

library(shiny)
library(shinydashboard)

server <- function(input, output) { }

ui <- dashboardPage(
  dashboardHeader(title = "Dashboard", titleWidth = 290),  
  dashboardSidebar(
    width = 290,
    sidebarMenu(
      menuItem(
        "Multiple Incident Analysis",
        tabName = "dashboard",
        icon = icon("th"),      
      div(id = "mult", splitLayout(cellWidths = c("44%", "31%", "25%"),
                                   dateInput("datefrom", "Date From:", format = "mm/dd/yyyy", Sys.Date()-5),
                                   textInput("datefrom_hour", "Hour",
                                             value = "12:00"),
                                   textInput("datefrom_noon","AM/PM", value = "AM")))), 
      menuItem(
        "Multiple Incident Analysis2",
        tabName = "dashboard2",
        icon = icon("th"),  
      div(id = "mult2", splitLayout(cellWidths = c("44%", "31%", "25%"),
                      dateInput("dateto", "Date To:", format = "mm/dd/yyyy"),
                      textInput("dateto_hour", "Hour",
                                value = "11:59"),
                      textInput("dateto_noon","AM/PM", value = "PM")))),
      menuItem("Single Analysis", 
               tabName = "widgets", 
               icon = icon("th"),
      div(id = "single",  numericInput("tckt", "Ticket Number : ", 12345,  width = 290))),
      submitButton("Submit", width = "290")
    )),  
  dashboardBody()
)

shinyApp(ui, server)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!