【问题标题】:Switch between the tabItems shiny dashboard在 tabItems 闪亮的仪表板之间切换
【发布时间】:2016-12-19 21:59:09
【问题描述】:

我正在创建一个闪亮的仪表板,我创建了 3 个 tabItems 问题是,当我单击其中一个 menuItem 时,我无法再次单击,我无法在 tabItems 之间切换。有人能帮助我吗 代码 R #用户界面

 library(shiny)
 library(shinydashboard)

 shinyUI(dashboardPage(skin = "black",
 dashboardHeader(title = h4("Tableau de bord des élections",style =      "color:navy"),
 titleWidth = 300
 ),
 dashboardSidebar(id="", 
 menuItem(h4(strong("Dashboard", align = "center")), tabName = "dashboard"),
 menuItem(h4(strong("Prédiction")), tabName = "Prédiction"),
 menuItem(h4(strong("Interprétation")), tabName = "Interprétation")),



 dashboardBody(
    tabItems(
        tabItem(tabName = "dashboard",h2("Analyse du comportement électoral  des citoyens tunisiens", align="center",style = "color:navy") ),

        tabItem(tabName = "Prédiction", h2("Prédiction du vote",    align="center",style = "color:blue")),
        tabItem(tabName = "Interprétation", h2("Interprétation"))

        )
        )))

【问题讨论】:

  • 能否包含您正在使用的代码或产生相同问题的示例? Example
  • 在我用来创建 tabItems @Sam 的代码 R 之上

标签: r tabitem shinydashboard menu-items


【解决方案1】:

我知道您的问题已经解决,并且您可能不会在大约 1 年后更改您的代码,但对于像我这样遇到此问题的其他人,我有一个更简单的解决方案。

您必须将所有“menuItem”包装在 sideBarMenu() 函数中。这将解决问题并使菜单中的项目更大。

library(shiny)
library(shinydashboard)

shinyUI(dashboardPage(skin = "black",
dashboardHeader(title = h4("Tableau de bord des élections",style =      
"color:navy"),
titleWidth = 300
),
dashboardSidebar(id="", sidebarMenu(
menuItem(h4(strong("Dashboard", align = "center")), tabName = "dashboard"),
menuItem(h4(strong("Prédiction")), tabName = "Prédiction"),
menuItem(h4(strong("Interprétation")), tabName = "Interprétation"))),

dashboardBody(
tabItems(
    tabItem(tabName = "dashboard",h2("Analyse du comportement électoral  des citoyens tunisiens", align="center",style = "color:navy") ),

    tabItem(tabName = "Prédiction", h2("Prédiction du vote",    align="center",style = "color:blue")),
    tabItem(tabName = "Interprétation", h2("Interprétation"))

    )
)))

【讨论】:

    【解决方案2】:

    很高兴知道我不是唯一遇到此问题的人!如果我正确理解您的问题,几个月前我遇到了同样的问题 - Switching between menuSubItems in shinyDashboard。尝试更改您的侧边栏代码以添加以下内容:(我当然不是这个 sn-p 的作者 - 但它解决了我的问题)

    dashboardSidebar(id="", 
                     tags$head(
                       tags$script(
                         HTML(
                           "
                            $(document).ready(function(){
                              // Bind classes to menu items, easiet to fill in manually
                              var ids = ['dashboard','Prédiction','Interprétation'];
                              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');
                              })
                            })
                            "
                         )
                       )
                     ),
    
                     menuItem(h4(strong("Dashboard", align = "center")), tabName = "dashboard"),
                     menuItem(h4(strong("Prédiction")), tabName = "Prédiction"),
                     menuItem(h4(strong("Interprétation")), tabName = "Interprétation"))
    

    如果您添加新选项卡,您可以将它们的 tabNames 添加到 var ids 行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 2016-05-02
      • 2018-06-15
      • 2019-06-20
      相关资源
      最近更新 更多