在我与RShiny的第一个项目中,我遇到了使用金字塔库(https://cran.r-project.org/web/packages/pyramid/index.html)的问题。 代码执行没有错误,但我没有在闪亮的应用程序中获得显示结果。
以下是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 :(得分:1)
问题不在于pyramid
库,而在于ui
设计。请参阅jsfiddle,您需要摆脱shinyUI
和fluidPage
,将其替换为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)