2016-08-12 96 views
2

我在创建一个闪亮的闪存的过程中,我创建3个tabItems 问题是,当我点击其中一个menuItem我不能再次点击,我无法切换在tabItems之间。有人可以帮我请 的编码R #UI切换tabItems闪亮的仪表板

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")) 

     ) 
     ))) 
+0

您能否包含您正在使用的代码或产生相同问题的示例? [Example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) – Sam

+0

在我用来创建tabItems @Sam的代码R之上 – Asma

回答

0

好知道我不是谁的碰上这个问题只有一个!如果我正确理解你的问题,几个月前我也遇到了同样的问题 - Switching between menuSubItems in shinyDashboard。试着改变你的侧边栏的代码添加此:(我当然不是这个片段的作者 - 但它解决了我的问题)

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线。

+0

非常感谢你的工作:D – Asma

0

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

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

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")) 

    ) 
)))