I want to display a table (with a column name, a number of unique values, a unique value) for a zero variance dataset (no. of unique values =< 1). But when I run this code in shiny, I get this error.
Warning: Error in : arguments imply differing number of rows: 2, 5, 3, 6
library(shiny)
library(shinydashboard)
library(DT)
library(caret)
ui <- dashboardPage(
   skin = "black",
   dashboardHeader(title = "data"),
   dashboardSidebar(
      sidebarMenu(
         fileInput("Table1", "Historical Data"),
         radioButtons("sep", "Separator", choices = c(Comma = ",", Semicolon = ";", 
         Tab = "\t", Pipe="|"), selected = ","),
            menuItem("Data Overview", tabName = "data_view", icon = icon("table"))
       )
    ),
   dashboardBody(
      tabItems(
         tabItem(tabName = "data_view",
            fluidRow(
               box(title = "Zero Variance Variables", width = 12, solidHeader = TRUE,
               status = "primary", collapsible = TRUE, DT::DTOutput("uniq_data")))
             )
        )
    )
)
server <- function(input, output, session) { 
  ## initialize
  rv <- reactiveValues()
  ## update when dataset changes
  observe({
    rv$Train <- read.table(req(input$Table1)$datapath, fill = TRUE, header = TRUE, 
                           sep=input$sep, na.strings = c(""," ", NA), 
                           stringsAsFactors = TRUE)
  }) 
  col_uniq <- reactive({
    nzv <- nearZeroVar(rv$Train)
    df1 <- rv$Train[, nzv] 
    d <- data.frame(names(df1), sapply(df1, function(x) length(unique(x[!is.na(x)]))))
    names(d) <- c("Variable", "No. of Uniques") 
    as <- sapply(df1, function(x) length(unique(x))) > 1
    as1 <- df1[, as]
    as2 <- data.frame(names(as1),sapply(as1, function(x) unique(x)))
    names(as2) <- c("Variable", "Unique Value")
    join <- merge(d, as2, by.x = "Variable", by.y = "Variable", all.x = TRUE)
    return(join)
  })
  output$uniq_data <- DT::renderDT({
    dclas <- DT::datatable(col_uniq(), options = list(scrollX = TRUE))
  })
}
shinyApp(ui, server)  
Thanks, Balaji

 
    