Error in divTag$attribs : $ operator is invalid for atomic vectors

So this code works perfectly in my IDE, but when I put it on my shiny server it returns the following error:

Error in divTag$attribs : $ operator is invalid for atomic vectors

What is going on?

## This script will be ablle to query an agents number &/ name and pull up the statistics on how healthy and agents book is.

if(exists("Item") == FALSE) {
  source("global.R",local = FALSE)
} else if(exists("Item") == TRUE) {
  
}
library(shinydashboard)
library(DT)
library(shiny)
library(dplyr)
#define UI dataset viewer application
ui<- fluidPage(
  br(),
  tabsetPanel( "mainPanel",
    tabPanel( "All Agents", br(), tags$p(strong("Agent Book Health")),
    # open up the base agent health file
    mainPanel(
      div(DT::dataTableOutput("AllAgents"),
          style = "font-size:100%; width:100%")
    )
  ),
    tabPanel("Individual Agent",
      shinyUI(
        verticalLayout(
          br(), tags$p(strong("Individual Agent & Policies")),
          sidebarLayout(  
            sidebarPanel(
              fluidRow(
                textInput(inputId = "agtNum",label = NULL ,placeholder = "Enter Agent number here"),
                helpText(
                  tags$em("Note:  Enter agent number NOT agent name")
                )
              )
            ),
            mainPanel(
              #summary of Agent from main tab
              h4("Agent Summary"),
              tableOutput(outputId = "AgtSum")
            )
          )
        )
      ),
      # open up individual policies to the files
      mainPanel(
        div(DT::dataTableOutput("indAgtResults"),
            style = "font-size:70%; width:50%")
      )
    ),
    tabPanel("Individual Policy",
      shinyUI(
        verticalLayout(
          br(), tags$p(strong("Individual Policies & Line Items")),
          sidebarLayout(
            sidebarPanel(
              fluidRow(
                textInput(inputId = "polNum", label = NULL, placeholder = "Enter Root number here"),
                helpText(tags$em("Note: The root number must include all 6 digits e.g. 000107"))
              )
            ),
            mainPanel(
              div(DT::dataTableOutput("indPolResults"),
                  style = "font-size:70%; width:50%")
            )
          )
        )
      ),
      mainPanel(
        #enter code for Policy Summary here.
      )
    )
  )
)
server <- function(input,output) {
  agents <- reactive ({
    agent <- as.data.frame(table(Policy$Agent)) 
    agtNo <- Policy[!duplicated(Policy["Agent"]), ]
    agtNo <- agtNo[order(agtNo$Agent),]
    sum1 <- aggregate(ActPrem~Agent, Policy, sum)
    sum2 <- aggregate(CorrPrem~Agent, Policy, sum)
    premium <- merge(sum1,sum2)
    premium <- transform(premium, Factor = CorrPrem / ActPrem)
    premium$Agent <- NULL
    round(premium$Factor, digits = 3)
    cbind(agtNo[8],agent, premium, deparse.level = 1)
  })
  output$AllAgents <- DT::renderDataTable(
    DT::datatable(agents(), rownames = FALSE, colnames = c("Agent Number","Agent","No. of Policies","Actual Premium","Indicated Premium","Health Factor"), 
      extensions = c('Buttons','FixedHeader'), options = list(lengthMenu = c(100,150,200), pageLength = 150, class = 'cell-border', 
        fixedHeader = TRUE)
    ) %>% formatRound(columns="Factor", digits = 3)
  )
  agtSummary <- reactive({
    Policy[Policy$AgtNo == input$agtNum,c(1,5,6,9,12:14,17,19,21:23,25:26,29,32,34,36:42)]
  })
  agtSummary1 <- reactive({
    filter(agents(), agents()$AgtNo == input$agtNum)
    #colnames(agents())[colnames(agents())=="AgtNo"] <- "Agent Number"
    #colnames(Policy)[colnames(Policy)=="Terr"] <- "Territory"
    #colnames(Item)[colnames(Item)=="CombISCorr"] <- "ISCorr"
    #colnames(Item)[colnames(Item)=="Prem"] <- "ActPrem"
    #colnames(Item)[colnames(Item)=="Corr"] <- "CorrFac"
  })
  output$indAgtResults <- DT::renderDataTable(
    DT::datatable(agtSummary(), rownames = FALSE, colnames = c("Root Number","Renew Date","Inusred","Policy Discount Factor","Insurance Score",
      "Loyalty","Loyalty Factor","Payment Factor","Defensible Space Factor","Item Age Factor","Territory","Territory Factor","IRPM","IRPM Factor",
      "Insured Age Factor","Loss Ratio Facotr","Protection Class Factor","Policy Size Factor","Actual Premium","Total Correction Factor",
      "Correction Dollar Difference", "Indicated Premium", "Underwriting percent Gain","Underwriting Dollar Gain"),
      extensions = c('Buttons','FixedHeader'), options = list(lengthMenu = c(100,150,200), pageLength = 150, 
      class = 'cell-border', fixedHeader = TRUE))%>%formatStyle(c('ISCorr','LoyCorr','PmtCorr','DSCorr','ItmAgeCorr','TerrCorr','IRPMCorr','InsAgeCorr','LRCorr','PCCorr','PolSizeCorr','CorrFac'),
                                                                color = styleInterval(c(.85,.95,.99999,1.0,1.05),c('white','black','black','black','black','white')), 
                                                                backgroundColor = styleInterval(c(.75,.85,.95,.99999,1.0,1.05,1.15),c('darkgreen','green','lime','lightgreen','white','pink','red','darkred')), fontWeight = 'bold')
  )
  output$AgtSum <- renderTable({
    head(agtSummary1()
    )
  })
  
  
}
shinyApp(ui = ui, server = server)

Try to remove the parameter "mainPanel" from tabsetPanel, that is:

tabsetPanel(
tabPanel( "All Agents", br(), tags$p(strong("Agent Book Health")),

alternatively you can tag the parameter, which is always a good practice:
tabsetPanel( id= "mainPanel", ...

1 Like

That fixed it thanks!

this fixes it, but I don't like where this puts the summary table, Sir Wries's solution is the one I employed. Thanks for the help!