R shiny sidebarMenu help me!!

I would like to expand my sidebarMenu using javascript, how can I do this?

          sidebarMenu(    <----------------------------------- This menu
            id = 'menuFiltro',
            menuItem(
                     text = "Filtro",
                     icon = icon('filter'),
                     selectInput(inputId = 'filterEquipamentosComboBox',label = 'Equipamento',choices = c(''),multiple = T),
                     dateInput('filterDateDe','Data De',width = '100%',value = Sys.Date(),format = "dd/mm/yyyy"),
                     div(align = "center",style = 'width: 100%;',timeInput(inputId = 'filterTimeDe','HH:MM',value = strptime("00:00:00", "%T"),seconds = F)),
                     dateInput('filterDateAte','Data Até',width = '100%',value = Sys.Date(),format = "dd/mm/yyyy"),
                     div(align = "center",style = 'width: 100%;',timeInput(inputId = 'filterTimeAte','HH:MM',value = strptime("23:59:59", "%T"),seconds = F)),
                     div(style = 'width: 100%; height:60px;',
                         div( style = 'float: left;',actionButton('btActiveFilter','Filtrar',icon = icon('check'))),
                         div( style = 'float: left;',actionButton('btClearFilte','Limpar',icon = icon('eraser')))  
                     ),
                     br()
            )
          ),

shinyjs is a good library for javascript effects within shiny

yes, but i don't know how do it give a example

i'm using library shinydashboard sidebarMenu!

Doesn't the arrow pointing down next to filtro let the items you highlighted collapse ?

I don't think you understand, I want to do this in javascript, not by the shiny UI, I want to collapse and show it, now I don't know the script for that.

so when would your code collapse it and when would it show it?, or should it be constantly collapsing and showing in an endless automated loop ?

No javascript needed:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(), 
  dashboardSidebar(
    sidebarMenu(
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
      menuItem("Widgets", icon = icon("th"), tabName = "widgets"),
      shinydashboard:::menuOutput("myfluctuatingmenuitem")
    ),
    textOutput("res")
  ),
  dashboardBody(
    tabItems(
      tabItem("dashboard", "Dashboard tab content"),
      tabItem("widgets", "Widgets tab content"),
      tabItem("subitem1", "Sub-item 1 tab content"),
      tabItem("subitem2", "Sub-item 2 tab content") 
    )
  )
)

server <- function(input, output, session) {
  mytoggle <<- TRUE

  output$myfluctuatingmenuitem <- renderMenu({
    invalidateLater(millis = 500)
  
  if(mytoggle)   {
    print("open")
    mytoggle<<-FALSE
      menuItem("Charts", icon = icon("bar-chart-o"), startExpanded = TRUE,
             menuSubItem("Sub-item 1", tabName = "subitem1"),
             menuSubItem("Sub-item 2", tabName = "subitem2"))
   } else {
     print("closed")
     mytoggle<<-TRUE
   menuItem("Charts", icon = icon("bar-chart-o"), startExpanded = FALSE,
            menuSubItem("Sub-item 1", tabName = "subitem1"),
            menuSubItem("Sub-item 2", tabName = "subitem2"))}
    }
  )
  output$res <- renderText({
    req(input$sidebarItemExpanded)
    paste("Expanded menuItem:", input$sidebarItemExpanded)
  })
}

shinyApp(ui, server)

it's perfect, thank you =D

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.