【问题标题】:Shiny Dashboard Error with Sidebar SubItems侧边栏子项的闪亮仪表板错误
【发布时间】:2018-12-24 03:32:18
【问题描述】:

以下是绘图的一些示例数据:

Female = c(23,56,77)
Male = c(33,55,22)
Canada = c(44,12,3)
US = c(47,14,9)

Stages = c("Application", "Interview", "Test")

masterFemale = data.frame(Stage, Female, Male)
Country = data.frame(Stages, Canada, US)

我不断收到错误

validateTabName(tabName) 中的错误:tabName 不能有 '.'在里面。

但我不知道它在说什么。我检查了代码中的括号和逗号,逻辑对我来说很有意义。有什么遗漏吗?

    ##Dashboard Header-------------
    header <- dashboardHeader(
      title = "My Dashboard")

    ##Dashboard Sidebar----------------
    sidebar <- dashboardSidebar(
      sidebarMenu(
        menuItem("Dashboard",tabName = "dashboard",
                 menuSubItem('Applicants',
                             tabName = 'applicants',
                             icon = icon("user", lib = "glyphicon")),
                 menuSubItem('Demographics',
                             tabName = 'demographics',
                             icon = icon("globe"))
                 ),
        menuItem("Job Positions", tabName = "jobposition",
                 menuSubItem('Associate',
                             tabName = 'associate',
                             icon = icon('address-card'))
        )
      )
    )

##Dashboard Sidebar----------------
sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Dashboard",tabName = "dashboard",
             menuSubItem('Applicants',
                         tabName = 'applicants',
                         icon = icon("user", lib = "glyphicon")),
             menuSubItem('Demographics',
                         tabName = 'demographics',
                         icon = icon("globe"))
             ),
    menuItem("Job Positions", tabName = "jobposition",
             menuSubItem('Associate',
                         tabName = 'associate',
                         icon = icon('address-card'))
    )
  )
)

##Dashboard Body-------------------
body <- dashboardBody(
  tabItems(
    # Dashboard Tab Content
    tabItem(tabName = "applicants",
            fluidRow(
              #Requires Attention Value Box
              valueBoxOutput("attentionbox"),
              #Applicant to Hire Avg TIme
              valueBoxOutput("hireAvgTime"),
              #Proportion of Women
              valueBoxOutput("WomenPercent"))
            ,
              fluidRow(
                column(width = 12,
              #Applicant Stage Plot
              box(
                title = ("Applicant Stages"),
                status = "warning",
                plotlyOutput("stageplot")
              ),
              #Avg Skill Score Plot
              box(
                title = ("Average Skill Score"),
                status = "warning",
                plotlyOutput("AvgSkillScore")
              ))
            )
    ),
    tabItem(tabname = 'demographics',
            fluidRow(
              tabBox(
                title = "",
                id = "tabset1", height = "250px",
                tabPanel("Gender", plot_ly(masterFemale, x = ~Stage, y = ~Female, type = 'bar', name = 'Female', hoverinfo = 'y') %>%
                           add_trace(y = masterFemale$Male, 
                                     name = 'Male',
                                     hoverinfo = 'y') %>%
                           layout(
                             yaxis = list(title = 'Number of Applicants'),
                             barmode = 'group',
                             margin = list(b = 170)) %>%
                           config(displayModeBar = F)),
                tabPanel("Country", plot_ly(masterCan, x = ~Stage, y = ~CAN, type = 'bar', name = 'CAN', hoverinfo = 'y') %>%
                           add_trace(y = ~US, name = 'US', hoverinfo = 'y') %>%
                           layout(
                             yaxis = list(title = 'Number of Applicants'),
                             barmode = 'group',
                             margin = list(b = 170)) %>%
                           config(displayModeBar = F)) #,
                #tabPanel("Education")
              ))

    ),

    # Associate Tab Content
    tabItem(tabName = "associate",
            fluidPage(
              box(title = "Card Information", height = 300, "Text"),

              #Main Box for Candidate
              uiOutput("candidates")
            )
    )
  )
)

ui <- dashboardPage(
  skin = "yellow",
  header,
  sidebar,
  body
)
shinyApp(ui, server)

在添加 menuSubitems 之前,其余代码和绘图工作正常。在我添加tabItem(tabname = 'demographics' 之后,它停止工作并且弹出了这个错误。任何帮助将不胜感激,谢谢!

【问题讨论】:

  • 如果我从标签中删除plot_ly,所有的工作都对我有用(因为你没有提供任何数据,所以我把它注释掉了)
  • 嘿,非常感谢您的提示!你对我如何在仍然使用 tabBoxes 的同时将 plotly 代码移动到服务器有什么建议吗?
  • 我猜它可能是您的plotly 代码,我需要一些masterFemalemasterCan 的示例数据来完全重现问题
  • @PorkChop 感谢您尝试与我一起解决这个问题。我在问题的顶部添加了一些示例数据。如果有任何问题请告诉我

标签: shiny shinydashboard


【解决方案1】:

看看这个:

library(shinydashboard)
library(shiny)
library(plotly)

Female = c(23,56,77)
Male = c(33,55,22)
Canada = c(44,12,3)
US = c(47,14,9)

Stages = c("Application", "Interview", "Test")
masterFemale = data.frame(Stages, Female, Male)
Country = data.frame(Stages, Canada, US)

##Dashboard Header-------------
header <- dashboardHeader(title = "My Dashboard")

##Dashboard Sidebar----------------
sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Dashboard",tabName = "dashboard",
             menuSubItem('Applicants',
                         tabName = 'applicants',
                         icon = icon("user", lib = "glyphicon")),
             menuSubItem('Demographics',
                         tabName = 'demographics',
                         icon = icon("globe"))
    ),
    menuItem("Job Positions", tabName = "jobposition",
             menuSubItem('Associate',
                         tabName = 'associate',
                         icon = icon('address-card'))
    )
  )
)

##Dashboard Body-------------------
body <- dashboardBody(
  tabItems(
    # Dashboard Tab Content
    tabItem(tabName = "applicants",
            fluidRow(
              #Requires Attention Value Box
              valueBoxOutput("attentionbox"),
              #Applicant to Hire Avg TIme
              valueBoxOutput("hireAvgTime"),
              #Proportion of Women
              valueBoxOutput("WomenPercent"))
            ,
            fluidRow(
              column(width = 12,
                     #Applicant Stage Plot
                     box(
                       title = ("Applicant Stages"),
                       status = "warning",
                       plotlyOutput("stageplot")
                     ),
                     #Avg Skill Score Plot
                     box(
                       title = ("Average Skill Score"),
                       status = "warning",
                       plotlyOutput("AvgSkillScore")
                     ))
            )
    ),


    # Associate Tab Content
    tabItem(tabName = "demographics",
            fluidRow(
              tabBox(
                # Title can include an icon
                title = tagList( ""),
                tabPanel("Tab1",
                         plotlyOutput("masterFemale")
                ),
                tabPanel("Tab2", plotlyOutput("masterCan"))
              )
            )),

    # Associate Tab Content
    tabItem(tabName = "associate",
            fluidPage(
              box(title = "Card Information", height = 300, "Text"),
              #Main Box for Candidate
              uiOutput("candidates")
            )
    )
  )
)

ui <- dashboardPage(
  skin = "yellow",
  header,
  sidebar,
  body
)


server <- function(input, output, session){

  output$masterFemale <- renderPlotly(

    plot_ly(masterFemale, x = ~ Stages, y = ~Female, type = 'bar', name = 'Female', hoverinfo = 'y') %>%
      add_trace(y = masterFemale$Male,name = 'Male',hoverinfo = 'y') %>%
      layout(
        yaxis = list(title = 'Number of Applicants'),
        barmode = 'group',
        margin = list(b = 170)) %>%
      config(displayModeBar = F)

  )

  output$masterCan <- renderPlotly(

    plot_ly(Country, x = ~Stages, y = ~Canada, type = 'bar', name = 'CAN', hoverinfo = 'y') %>%
      add_trace(y = ~US, name = 'US', hoverinfo = 'y') %>%
      layout(
        yaxis = list(title = 'Number of Applicants'),
        barmode = 'group',
        margin = list(b = 170)) %>%
      config(displayModeBar = F) 
  )
}

shinyApp(ui, server)

【讨论】:

  • 嘿猪排,这看起来很棒!是否可以将这些图表放入 tabBoxes 而不是 rstudio.github.io/shinydashboard/structure.html#tabbox ?那是我一直在努力的部分。如果没有,那太好了,非常感谢
  • 当然,我已经添加了编辑
  • 你是最棒的。
猜你喜欢
  • 2016-11-24
  • 1970-01-01
  • 2020-10-21
  • 1970-01-01
  • 1970-01-01
  • 2016-12-05
  • 2018-09-25
  • 2016-11-11
  • 2019-12-21
相关资源
最近更新 更多