Integrating tabItems with different id in shiny dashboard

shinydashboard

#1

I have tried to create two tabs in tab Items in shiny dashboard and each with different id. Each tabs uses one file to show case the reports. But when i added each tabs, contents are not showing after launching the app. I have attached the code for the app below. Please help me to find the problem whether it is from UI or SERVER side. Thanks in advance.

library(shiny)
library(shinydashboard)
library(data.table)
library(readr)
library(ggplot2)
options(scipen=999)
ui <- dashboardPage(
  dashboardHeader(title = "Churn Dashboard",
                  dropdownMenu(type = "messages",
                               messageItem(from = "A",message = "B"),
                               messageItem(from = "C",message = "D",icon = icon("question")),
                               messageItem(from = "E",message = "F")
                              ),
                  dropdownMenu(type = "notifications",
                               notificationItem(text="X",icon("users")),
                               notificationItem(text="Y",icon("truck"),status = "warning")
                              ),
                  dropdownMenu(type = "tasks",badgeStatus = "success",
                               taskItem(value = 90,color = "green","Z")
                              )
                  ),
  dashboardSidebar(
    sidebarMenu(id="tab",
      menuItem("Dashboard",tabName = "dashboard",icon = icon("dashboard")),
      menuItem("Training Model Summary",tabName = "trainingmodelsummary",icon = icon("th")),
      menuItem("Test Model Summary",tabName = "testmodelsummary",icon = icon("th")),
      menuItem("Data Reports",tabName = "datareports",icon = icon("th")),
      menuItem("Analytical Reports",tabName = "analyticalreports",icon = icon("users"))
    )
  ),
  dashboardBody(
    tabItems(
    tabItem(tabName = "dashboard",h2("CHURN RETENSION NOVEMBER - 2017")),
    tabItem(tabName = "trainingmodelsummary",h2("TRAINING SET MODEL SUMMARY"),
            fluidRow(
              valueBoxOutput("activeCustomers"),
              valueBoxOutput("nonChurners"),
              valueBoxOutput("churners")
            ),fluidRow(
              valueBoxOutput("low",width=4),
              valueBoxOutput("medium",width=4),
              valueBoxOutput("high",width=4)
            ),fluidRow(
              box(title = "ARPU Band Distribution" ,status = "primary" ,solidHeader = TRUE ,collapsible = TRUE 
                  ,plotOutput("plot2",height = 450)),
              box(title = "Churn Score Distribution" ,status = "primary" ,solidHeader = TRUE ,collapsible = TRUE
                  ,plotOutput("plot1",height = 450))
            )
            
    ),
    tabItem(tabName = "testmodelsummary",h2("TEST SET MODEL SUMMARY"),
            fluidRow(
              valueBoxOutput("activeCustomersT"),
              valueBoxOutput("nonChurnersT"),
              valueBoxOutput("churnersT")
            ),fluidRow(
              valueBoxOutput("lowT",width=4),
              valueBoxOutput("mediumT",width=4),
              valueBoxOutput("highT",width=4)
            ),fluidRow(
              box(title = "ARPU Band Distribution" ,status = "primary" ,solidHeader = TRUE ,collapsible = TRUE 
                  ,plotOutput("plot4",height = 450)),
              box(title = "Churn Score Distribution" ,status = "primary" ,solidHeader = TRUE ,collapsible = TRUE
                  ,plotOutput("plot3",height = 450))
            )
            
    ),
    tabItem(tabName = "datareports",
            box(title = "Data Reports" ,status = "primary" ,solidHeader = TRUE ,collapsible = TRUE 
                ,plotOutput("plot3",height = 450))
  ),
  tabItem(tabName = "analyticalreports",h2("Content for Analytical Reports"))
    )
  )
)
server <- function(input, output) {
  set.seed(122)
  histdata<-fread("D:/FULL_OUTER_HML.txt")
  histdata[,c(3:5,8,9)]<-lapply(histdata[,c(3:5,8,9)],factor)
  banddata<-as.data.frame(table(histdata$TRAIN_ASPU_STATUS))
  names(banddata)[1]<-"ASPU.Band"
  banddatatest<-as.data.frame(table(histdata$TEST_ASPU_STATUS))
  names(banddatatest)[1]<-"ASPU.Band"
  print(paste("first data",banddata,sep=""))
  print(paste("second data",banddatatest,sep=""))
  
  output$plot1<-renderPlot({
    ggplot(data=histdata, aes(histdata$TRAINCOC)) + 
      geom_histogram(breaks=seq(0, 100, by=10), 
                     col="red", 
                     aes(fill=..count..),
                     alpha = .2) + 
      scale_fill_gradient("Count", low="green", high="red")+
      scale_y_continuous(breaks = round(seq(0, 1000000, by = 100000),1))+
      labs(x="Churn Score",y="Count of Subscribers")
  })
  output$plot2<-renderPlot({
    ggplot(data=banddata, aes(x=ASPU.Band,y=Freq,fill=ASPU.Band)) + 
      geom_bar(stat="identity", position="dodge")+
      scale_y_continuous(breaks = round(seq(0, max(banddata$Freq), by = 50000),1))+
      labs(x="ARPU Band",y="Count of Subscribers")
  })
  
  actCustomers<-nrow(histdata)
  print(actCustomers)
  output$activeCustomers<-renderValueBox({
    valueBox(formatC(actCustomers, format="d", big.mark=',')
             ,"Active Customers"
             ,icon = icon("pie-chart")
             ,color ="green"
    )
  })
  
  nonChurn<-nrow(histdata[which(histdata$TRAINPREDICTED=="N"),])
  print(nonChurn)
  output$nonChurners<-renderValueBox({
    valueBox(formatC(nonChurn, format="d", big.mark=',')
             ,"Non Churn Customers"
             ,icon = icon("pie-chart")
             ,color ="green"
    )
  })
  
  churn<-nrow(histdata[which(histdata$TRAINPREDICTED=="Y"),])
  print(churn)
  output$churners<-renderValueBox({
    valueBox(formatC(churn, format="d", big.mark=',')
             ,"Churn Customers"
             ,icon = icon("pie-chart")
             ,color ="red"
    )
  })
  
  lowc<-nrow(histdata[which(histdata$TRAIN_ASPU_STATUS=="L"),])
  print(lowc)
  output$low<-renderValueBox({
    valueBox(formatC(lowc, format="d", big.mark=',')
             ,"Low Value Customers"
             ,icon = icon("eur")
             ,color ="red"
    )
  })
  
  mediumc<-nrow(histdata[which(histdata$TRAIN_ASPU_STATUS=="M"),])
  print(mediumc)
  output$medium<-renderValueBox({
    valueBox(formatC(mediumc, format="d", big.mark=',')
             ,"Medium Value Customers"
             ,icon = icon("eur")
             ,color ="orange"
    )
  })
  
  highc<-nrow(histdata[which(histdata$TRAIN_ASPU_STATUS=="H"),])
  print(highc)
  output$high<-renderValueBox({
    valueBox(formatC(highc, format="d", big.mark=',')
             ,"High Value Customers"
             ,icon = icon("eur")
             ,color ="green"
    )
  })
  
  
  output$plot3<-renderPlot({
    ggplot(data=histdata, aes(histdata$TESTCOC)) + 
      geom_histogram(breaks=seq(0, 100, by=10), 
                     col="red", 
                     aes(fill=..count..),
                     alpha = .2) + 
      scale_fill_gradient("Count", low="green", high="red")+
      scale_y_continuous(breaks = round(seq(0, 1000000, by = 100000),1))+
      labs(x="Churn Score",y="Count of Subscribers")
  })
  output$plot4<-renderPlot({
    ggplot(data=banddatatest, aes(x=ASPU.Band,y=Freq,fill=ASPU.Band)) + 
      geom_bar(stat="identity", position="dodge")+
      scale_y_continuous(breaks = round(seq(0, max(banddatatest$Freq), by = 50000),1))+
      labs(x="ARPU Band",y="Count of Subscribers")
  })
  
  actCustomersT<-nrow(histdata)
  output$activeCustomersT<-renderValueBox({
    valueBox(formatC(actCustomersT, format="d", big.mark=',')
             ,"Active Customers"
             ,icon = icon("pie-chart")
             ,color ="green"
    )
  })
  
  nonChurnT<-nrow(histdata[which(histdata$TESTPREDICTED=="N"),])
  output$nonChurnersT<-renderValueBox({
    valueBox(formatC(nonChurnT, format="d", big.mark=',')
             ,"Non Churn Customers"
             ,icon = icon("pie-chart")
             ,color ="green"
    )
  })
  
  churnT<-nrow(histdata[which(histdata$TESTPREDICTED=="Y"),])
  output$churnersT<-renderValueBox({
    valueBox(formatC(churnT, format="d", big.mark=',')
             ,"Churn Customers"
             ,icon = icon("pie-chart")
             ,color ="red"
    )
  })
  
  lowcT<-nrow(histdata[which(histdata$TEST_ASPU_STATUS=="L"),])
  output$lowT<-renderValueBox({
    valueBox(formatC(lowcT, format="d", big.mark=',')
             ,"Low Value Customers"
             ,icon = icon("eur")
             ,color ="red"
    )
  })
  
  mediumcT<-nrow(histdata[which(histdata$TEST_ASPU_STATUS=="M"),])
  output$mediumT<-renderValueBox({
    valueBox(formatC(mediumcT, format="d", big.mark=',')
             ,"Medium Value Customers"
             ,icon = icon("eur")
             ,color ="orange"
    )
  })
  
  highcT<-nrow(histdata[which(histdata$TEST_ASPU_STATUS=="H"),])
  output$highT<-renderValueBox({
    valueBox(formatC(highcT, format="d", big.mark=',')
             ,"High Value Customers"
             ,icon = icon("eur")
             ,color ="green"
    )
  })
  
}
shinyApp(ui, server)

#2

Hi @vishnu43, you are much more likely to get help on here if you post a minimal reproducible example (check out the reprex package). This involved boiling down your app to just the problem. Often this will help you solve the issue on your own (as you remove pieces the issue may resolve itself). Right now, this is a ton of code to parse through and I am not able to reproduce it since I do not have access to your data.

It is also helpful to show any error messages that may be showing.