当menuSubItems出现在ShinyDashboard中时,tabItem取消激活menuItem

时间:2016-06-15 21:01:36

标签: r shiny shinydashboard

在开发ShinyDashboard侧边栏时,出于某种原因,无论何时将 menuSubItem 添加到 menuItem ,内容相对于父 menuItem tabName 已停用。默认内容似乎成为 menuSubItem 之一的内容。我想要点击Menu One时从 tabItem 显示的数据(在本例中为 Show Me! [第62行])。单击仅激活滑动功能。

有关于菜单和子菜单刷新的问题。我已相应修改了该代码。

library('shiny')
library('shinydashboard')
# Sidebar #############################
sidebar <- dashboardSidebar(
 tags$head(
    tags$script(
      HTML(
        "
        $(document).ready(function(){
          // Bind classes to menu items, easiet to fill in manually
          var ids = ['subItemOne','subItemTwo','subItemThree','subItemFour','menuOne','menuTwo'];
          for(i=0; i<ids.length; i++){
            $('a[data-value='+ids[i]+']').addClass('my_subitem_class');
          }

          // Register click handeler
          $('.my_subitem_class').on('click',function(){
            // Unactive menuSubItems
            $('.my_subitem_class').parent().removeClass('active');
          })
        })
        "
      )
    )
  ),
  width = 290,

  sidebarMenu(
    menuItem('Menu One', tabName = 'menuOne', icon = icon('line-chart'), 
        collapsible = 
            menuSubItem('Sub-Item One', tabName = 'subItemOne'),
            menuSubItem('Sub-Item Two', tabName = 'subItemTwo')
            )
  ),

  sidebarMenu(
    menuItem('Menu Two', tabName = 'menuTwo', icon = icon('users')
            # collapsible = 
           #    menuSubItem('Sub-Item Three', tabName = 'subItemThree'),
          #   menuSubItem('Sub-Item Four', tabName = 'subItemFour')
    )
  )

)
# Body #############################
body <- dashboardBody(

  tabItems(
    tabItem(tabName = 'subItemOne',
            h2('Selected Sub-Item One')
    ),
    tabItem(tabName = 'subItemTwo',
            h2('Selected Sub-Item Two')
    ),
    tabItem(tabName = 'subItemThree',
            h2('Selected Sub-Item Three')
    ),
    tabItem(tabName = 'subItemFour',
            h2('Selected Sub-Item Four')
    ),
 tabItem(tabName = 'menuOne',
            h2('Show Me!')
    ),
 tabItem(tabName = 'menuTwo',
            h2('m2')
    )

  )
)
# UI #############################
ui <- dashboardPage(
  dashboardHeader(title = 'Test', titleWidth = 290),
  sidebar,
  body
)
# Server #############################
server <- function(input, output){

}

shinyApp(ui, server)

我想要我的蛋糕并用这个来吃它!感谢。

0 个答案:

没有答案