Reputation: 93
During my first project with RShiny, I have an issue using the pyramid library ( https://cran.r-project.org/web/packages/pyramid/index.html ). The code is executed without error, but I do not obtain display result in the shiny app.
Here is the concerned code in server.R file and UI.R file :
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")))
)
)
)
))
And the output of 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")
Upvotes: 0
Views: 148
Reputation: 21425
The issue is not with the pyramid
library but with your ui
design. See this, you need to get rid of shinyUI
and fluidPage
, replace it with a dashboardPage
, add a header and a sidebar etc.
Here is an example taken from the link I posted:
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)
Upvotes: 1