侧边栏子项的闪亮仪表板错误

时间:2018-07-16 14:37:28

标签: shiny shinydashboard

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

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'后,它停止工作并且弹出此错误。任何帮助将不胜感激,谢谢!

1 个答案:

答案 0 :(得分: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)

enter image description here