【问题标题】:Display issue using RShiny and pyramid library使用 RShiny 和金字塔库显示问题
【发布时间】:2016-01-18 13:28:14
【问题描述】:

在我使用 RShiny 的第一个项目期间,我在使用金字塔库 (https://cran.r-project.org/web/packages/pyramid/index.html) 时遇到了问题。 代码执行没有错误,但我没有在闪亮的应用程序中获得显示结果。

这里是 server.R 文件和 UI.R 文件中的相关代码:

服务器.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")

【问题讨论】:

  • 请在您的帖子中添加一些数据(粘贴dput(staff)dput(staff[1:20,]) 的输出),以便我们运行示例。

标签: r shiny


【解决方案1】:

问题不在于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)

【讨论】:

  • 感谢您的回答 NiceE,此解决方案更简单。但是,我仍然找不到为什么不显示 tabItem (inside dashBoardbody) 之一。似乎 RShiny 正在捕获找到的最后一个 tabItem 并将其显示在以下“menuItem”中。我在想它可能来自 tabBox 的 id 参数(默认设置为“tabset1”)。你怎么看?
  • 不确定我是否理解,现在我在显示中看到两个 tabItem,一个只有“仪表板选项卡内容”文本,另一个是你的情节。要在它们之间切换,按钮位于侧边栏中。你认为缺少哪一个?
  • 我的原始代码有很多tabItem,其中一个没有显示在App中。这是由于 tabName 中的空格导致了错误,但与我原来的问题没有任何关系。感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-11
  • 2018-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多