2016-08-12 98 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")) 

    ) 
)))