2016-01-18 51 views
0

在我使用RShiny的第一個項目中,我有一個使用金字塔庫(https://cran.r-project.org/web/packages/pyramid/index.html)的問題。 代碼執行時沒有錯誤,但我沒有在閃亮的應用程序中獲得顯示結果。使用RShiny和金字塔庫的顯示問題

這裏是server.R文件和文件UI.R有關代碼:

server.R:

output$effectifStartAgrege <- renderPlot({ 
    staff <- read.xlsx('C:/file.xlsx', 1) 
    pyramid(staff, main = "Statistics") 
}) 

ui.R:

shinyUI(fluidPage(
    dashboardBody( 
     tabItems(
      tabItem(tabName = "Team D", 
       tabBox(
        title = "Team detailed compositions", 
        width = 400, 
        id = "tabset2", height = "250px", 
        tabPanel("START", "First tab content",              
        plotOutput("effectifStartAgrege")))       
        ) 
     ) 
    ) 
)) 

和輸出的dput(staff):

structure(list(Grade = structure(c(4L, 1L, 2L, 6L, 7L, 8L, 5L, 
9L, 3L), .Label = c("AD", "AE", "AS/ED", "I", "M", "S1", "S2", 
"S3", "SM"), class = "factor"), Assurance = c(6, 7, 0, 8, 7, 
0, 7, 2, 4), Pension = c(0, 10, 0, 2, 3, 0, 2, 1, 2), Analytics = c(3, 
3, 0, 2, 2, 0, 1, 1, 0)), .Names = c("Grade", "Assurance", "Pension", 
"Analytics"), row.names = c(NA, -9L), class = "data.frame") 
+0

請加一些數據(將'dput(staff)'或'dput(staff [1:20,])''的輸出粘貼到你的文章中,以便我們可以運行該示例。 – NicE

回答

1

The問題不在於pyramid庫,而在於您的ui設計。見this,你需要擺脫shinyUIfluidPage,具有dashboardPage更換,添加頁眉和側邊欄等

這裏是我發佈的鏈接採取一個例子:

library(shiny) 
library(pyramid) 
library(shinydashboard) 


sidebar <- dashboardSidebar(
    sidebarMenu(
    menuItem("Team D", tabName = "TeamD", icon = icon("dashboard")), 
    menuItem("Widgets", icon = icon("th"), tabName = "widgets", 
      badgeLabel = "new", badgeColor = "green") 
) 
) 

body <- dashboardBody(
    tabItems(
    tabItem(tabName = "widgets", 
      h2("Dashboard tab content") 
    ), 

    tabItem(tabName = "TeamD", 
      h2("test"), 
      tabBox(
       title = "Team detailed compositions", 
       width = 400, 
       id = "tabset2", height = "250px", 
       tabPanel("START", "First tab content",              
         plotOutput("effectifStartAgrege"))) 
    ) 
) 
) 

ui <-dashboardPage(
    dashboardHeader(title = "Simple tabs"), 
    sidebar, 
    body 
) 

server <- function(input, output) { 
    output$effectifStartAgrege <- renderPlot({ 
    pyramid(staff, main = "Statistics") 
    }) 
} 
shinyApp(ui,server) 
+0

感謝您的回答尼克,這種解決方案更簡單。 但是,我仍然無法找到爲什麼其中一個tabItem(內部dashBoardbody)沒有顯示。看起來RShiny正在捕獲找到的最後一個tabItem,並將其放在下面的「menuItem」中。我認爲它可能來自tabBox的id參數(默認設置爲「tabset1」)。你怎麼看 ? – Khalife

+0

不知道我明白了,現在我在我的顯示器中看到兩個tabItem,一個只有「儀表板選項卡內容」文本,另一個是您的情節。要在它們之間切換,按鈕位於邊欄中。你認爲哪一個失蹤? – NicE

+0

我原來的代碼有很多tabItem,其中一個沒有顯示在App中。這是由於tabName中導致錯誤的空間,但沒有鏈接到我原來的問題。謝謝你的幫助 ! – Khalife