Skip to content

Commit 079a58b

Browse files
committed
small tables for attribute totals
1 parent 71d5b6e commit 079a58b

3 files changed

Lines changed: 61 additions & 8 deletions

File tree

inst/shiny/global.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,15 @@ hist.info <- function(x, breaks) {
155155
for(i in seq(length(out$breaks) - 2)){
156156
barname <- append(barname, paste(out$breaks[i+1]+1, out$breaks[i+2], sep = "-"))
157157
}
158-
out <- out$counts
159-
names(out) <- barname
158+
159+
out$percent <- out$counts/sum(out$counts)
160+
names(out$counts) <- barname
161+
names(out$percent) <- barname
160162
return(out)
161163
}
164+
165+
attrtab <- function(obj, breaks) {
166+
tab <- hist.info(obj, breaks = breaks)
167+
tab < - rbind(tab, tab/sum(tab))
168+
rownames(tab) <- c("count", "percent")
169+
}

inst/shiny/server.R

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,11 +1441,50 @@ output$attrcheck <- renderUI({
14411441
})
14421442
outputOptions(output, "attrcheck", suspendWhenHidden = FALSE)
14431443

1444-
output$attrtbl <- renderDataTable({
1444+
output$attrtbl_lg <- renderDataTable({
14451445
dt <- nwdf()[, c("Names", input$attrcols)]
14461446
dt
14471447
}, options = list(pageLength = 10))
14481448

1449+
output$attrtbl_sm <- renderPrint({
1450+
ntbl <- length(input$attrcols)
1451+
if(ntbl == 0){return()}
1452+
attrname <- input$attrcols
1453+
tbl_list <- list()
1454+
if(ntbl == 1){
1455+
lvls <- length(unique(nwdf()[[attrname]]))
1456+
if(attrname %in% numattr() & lvls > 9){
1457+
tab <- hist(nwdf()[[attrname]], breaks = 10, plot = FALSE)
1458+
barname <- paste(tab$breaks[1:2], collapse = "-")
1459+
for(i in seq(length(tab$breaks) - 2)){
1460+
barname <- append(barname, paste(tab$breaks[i+1]+1, tab$breaks[i+2], sep = "-"))
1461+
}
1462+
tab <- tab$counts
1463+
names(tab) <- barname
1464+
} else {
1465+
tab <- table(nwdf()[[attrname]])
1466+
}
1467+
tbl_list[[attrname]] <- tab
1468+
} else {
1469+
for(a in attrname){
1470+
lvls <- length(unique(nwdf()[[a]]))
1471+
if(a %in% numattr() & lvls > 9){
1472+
tab <- hist(nwdf()[[a]], breaks = 10, plot = FALSE)
1473+
barname <- paste(tab$breaks[1:2], collapse = "-")
1474+
for(i in seq(length(tab$breaks) - 2)){
1475+
barname <- append(barname, paste(tab$breaks[i+1]+1, tab$breaks[i+2], sep = "-"))
1476+
}
1477+
tab <- tab$counts
1478+
names(tab) <- barname
1479+
} else {
1480+
tab <- table(nwdf()[[a]])
1481+
}
1482+
tbl_list[[a]] <- tab
1483+
}
1484+
}
1485+
tbl_list
1486+
})
1487+
14491488
output$attrhist <- renderPlot({
14501489
nplots <- length(input$attrcols)
14511490
if(nplots == 0){return()}
@@ -1458,7 +1497,8 @@ output$attrhist <- renderPlot({
14581497
col = "#076EC3", lwd = 2)
14591498
} else {
14601499
if(attrname %in% numattr() & lvls > 9){
1461-
tab <- hist.info(nwdf()[[attrname]], breaks = 10)
1500+
out <- hist.info(nwdf()[[attrname]], breaks = 10)
1501+
tab <- out$counts
14621502
} else {
14631503
tab <- table(nwdf()[[attrname]])
14641504
}

inst/shiny/ui.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,13 @@ fluidRow(
501501
)
502502
),
503503
tabPanel('Attributes', br(),
504-
conditionalPanel('input.attrview == "table"',
505-
dataTableOutput("attrtbl")
504+
conditionalPanel('input.attrview == "Large table"',
505+
dataTableOutput("attrtbl_lg")
506506
),
507-
conditionalPanel('input.attrview == "histogram"',
507+
conditionalPanel('input.attrview == "Small tables"',
508+
verbatimTextOutput("attrtbl_sm")
509+
),
510+
conditionalPanel('input.attrview == "Plot summaries"',
508511
tags$label("Type of plots"),
509512
helpText("Density plots will only be created for",
510513
"numeric attributes with more than nine",
@@ -760,7 +763,9 @@ fluidRow(
760763
label = "Download Plot", class = "btn-sm")),
761764
conditionalPanel(condition='input.plottabs == "Attributes"',
762765
selectInput("attrview", label = "View attributes in:",
763-
choices = c("table", "histogram")),
766+
choices = c("Large table",
767+
"Small tables",
768+
"Plot summaries")),
764769
br(),
765770
uiOutput("attrcheck")
766771
),

0 commit comments

Comments
 (0)