Skip to content

Commit 2e6e9b8

Browse files
committed
Merge pull request #61 from statnet/production
updates from Production
2 parents 6e27a6e + 1574253 commit 2e6e9b8

5 files changed

Lines changed: 88 additions & 43 deletions

File tree

inst/shiny/global.R

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,20 @@ stat.comparison <- function(statlist) {
149149
return(statvec)
150150
}
151151

152-
hist.info <- function(x, breaks) {
153-
out <- hist(x, breaks = breaks, plot = FALSE)
154-
barname <- paste(out$breaks[1:2], collapse = "-")
155-
for(i in seq(length(out$breaks) - 2)){
156-
barname <- append(barname, paste(out$breaks[i+1]+1, out$breaks[i+2], sep = "-"))
152+
attr.info <- function(df, colname, numattrs, breaks) {
153+
lvls <- length(unique(df[[colname]]))
154+
if(colname %in% numattrs & lvls > 9){
155+
tab <- hist(df[[colname]], breaks = breaks, plot = FALSE)
156+
barname <- paste(tab$breaks[1:2], collapse = "-")
157+
for(i in seq(length(tab$breaks) - 2)){
158+
barname <- append(barname, paste(tab$breaks[i+1]+1,
159+
tab$breaks[i+2], sep = "-"))
160+
}
161+
tab <- tab$counts
162+
names(tab) <- barname
163+
} else {
164+
tab <- table(df[[colname]])
157165
}
158-
out <- out$counts
159-
names(out) <- barname
160-
return(out)
166+
return(tab)
161167
}
168+

inst/shiny/server.R

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,11 +1441,33 @@ 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+
tab <- attr.info(df = nwdf(), colname = attrname,
1456+
numattrs = numattr(), breaks = 10)
1457+
tbl_list[[attrname]] <- tab
1458+
} else {
1459+
for(a in attrname){
1460+
tab <- attr.info(df = nwdf(), colname = a,
1461+
numattrs = numattr(), breaks = 10)
1462+
tbl_list[[a]] <- tab
1463+
}
1464+
}
1465+
for(a in attrname){
1466+
print(a, quote = FALSE)
1467+
print(tbl_list[[a]])
1468+
}
1469+
})
1470+
14491471
output$attrhist <- renderPlot({
14501472
nplots <- length(input$attrcols)
14511473
if(nplots == 0){return()}
@@ -1457,15 +1479,12 @@ output$attrhist <- renderPlot({
14571479
plot(density(nwdf()[[attrname]]), main = attrname,
14581480
col = "#076EC3", lwd = 2)
14591481
} else {
1460-
if(attrname %in% numattr() & lvls > 9){
1461-
tab <- hist.info(nwdf()[[attrname]], breaks = 10)
1462-
} else {
1463-
tab <- table(nwdf()[[attrname]])
1464-
}
1482+
tab <- attr.info(df = nwdf(), colname = attrname,
1483+
numattrs = numattr(), breaks = 10)
14651484
if(input$attrhistaxis == "percent"){
14661485
tab <- tab/sum(tab)
14671486
}
1468-
barplot(tab, xlab = attrname, col = histblue)
1487+
barplot(tab, main = attrname, col = histblue)
14691488
}
14701489
} else {
14711490
r <- ceiling(nplots/2)
@@ -1475,15 +1494,12 @@ output$attrhist <- renderPlot({
14751494
if(input$attrhistaxis == "density" & a %in% numattr() & lvls > 9){
14761495
plot(density(nwdf()[[a]]), main = a, col = "#076EC3", lwd = 2)
14771496
} else {
1478-
if(a %in% numattr() & lvls > 9){
1479-
tab <- hist.info(nwdf()[[a]], breaks = 10)
1480-
} else {
1481-
tab <- table(nwdf()[[a]])
1482-
}
1483-
if(input$attrhistaxis == "percent"){
1484-
tab <- tab/sum(tab)
1485-
}
1486-
barplot(tab, xlab = a, col = histblue)
1497+
tab <- attr.info(df = nwdf(), colname = a,
1498+
numattrs = numattr(), breaks = 10)
1499+
if(input$attrhistaxis == "percent"){
1500+
tab <- tab/sum(tab)
1501+
}
1502+
barplot(tab, main = a, col = histblue)
14871503
}
14881504
}
14891505
}
@@ -2934,15 +2950,19 @@ output$listofterms <- renderUI({
29342950
choices = c("Select a term" = "", current.terms))
29352951
})
29362952

2937-
output$termdoc <- renderPrint({
2953+
output$termdoc <- renderUI({
29382954
myterm <- input$chooseterm
29392955
if(is.null(myterm)){
2940-
return(cat("Select or search for a term in the menu above."))
2941-
}
2942-
if(myterm == ""){
2943-
return(cat("Select or search for a term in the menu above."))
2944-
}
2945-
search.ergmTerms(name=myterm)
2956+
return(p("Select or search for a term in the menu above."))
2957+
} else if(myterm == ""){
2958+
return(p("Select or search for a term in the menu above."))
2959+
}
2960+
chrvec <- capture.output(search.ergmTerms(name = myterm))
2961+
desc <- strsplit(chrvec[3], split = "_")
2962+
p(chrvec[1], br(),br(),
2963+
strong(chrvec[2]), br(),br(),
2964+
em(desc[[1]][2]), desc[[1]][3], br(),
2965+
chrvec[4])
29462966
})
29472967

29482968
observe({

inst/shiny/ui.R

Lines changed: 16 additions & 9 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
),
@@ -899,7 +904,7 @@ actionLink('plotright', icon=icon('arrow-right', class='fa-2x'), label=NULL)
899904
fluidRow(
900905
column(12,
901906
a("Commonly used ergm terms",
902-
href = "http://statnet.csde.washington.edu/EpiModel/nme/d2-ergmterms.html",
907+
href = "http://statnet.github.io/nme/ergmterms.html",
903908
target = "_blank"), br(),
904909
a("Term cross-reference tables",
905910
href = "http://cran.r-project.org/web/packages/ergm/vignettes/ergm-term-crossRef.html",
@@ -916,7 +921,7 @@ actionLink('plotright', icon=icon('arrow-right', class='fa-2x'), label=NULL)
916921
fluidRow(
917922
column(12,
918923
div(id="termdocbox",
919-
verbatimTextOutput("termdoc")
924+
uiOutput("termdoc")
920925
),
921926
div(id = "termexpand",
922927
icon(name = "angle-double-up"))
@@ -931,12 +936,13 @@ actionLink('plotright', icon=icon('arrow-right', class='fa-2x'), label=NULL)
931936
fluidRow(class = "shiftright",
932937
column(3, style = "padding-left: 0;",
933938
inlineSelectInput('controltype',label = NULL,
934-
choices = c("MCMC","MCMLE"),
939+
choices = c("MCMC"),
935940
style="margin:10px 0px;")),
936941
column(5,
937942
checkboxInput('controldefault', 'Use default options', value = TRUE))
938943
),
939-
conditionalPanel(condition = "input.controltype == 'MCMC'", class = "shiftright",
944+
conditionalPanel(condition = "input.controltype == 'MCMC'",
945+
class = "shiftright gray", id = "mcmcopt1",
940946
fluidRow(
941947
column(4,
942948
span("Interval:"),
@@ -1179,7 +1185,8 @@ tabPanel(title='Simulations', value='tab7',
11791185
column(7,
11801186
checkboxInput('simcontroldefault','Use default options', value=TRUE))
11811187
),
1182-
conditionalPanel(condition="input.simcontroltype == 'MCMC'", class="shiftright",
1188+
conditionalPanel(condition="input.simcontroltype == 'MCMC'",
1189+
class="shiftright gray", id = "mcmcopt2",
11831190
fluidRow(
11841191
column(5,
11851192
span("Interval:"),

inst/shiny/www/alert.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ $(document).ready(function(){
221221
$("#mcmchelpbox").toggle(500);
222222
});
223223

224+
$("#controldefault").click(function(){
225+
$("#mcmcopt1").toggleClass("gray");
226+
})
227+
$("#simcontroldefault").click(function(){
228+
$("#mcmcopt2").toggleClass("gray");
229+
})
230+
224231
});
225232

226233

inst/shiny/www/style.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ div .mcmcopt {
309309
}
310310

311311
.inlineselect {
312-
width:100px;
313-
line-height:20px;
312+
width:100px;
313+
line-height:20px;
314314
font-size:12px;
315315
}
316316

@@ -341,6 +341,7 @@ div.placeholder {
341341
#termdoc {
342342
background:#FFFFFF;
343343
border:none;
344+
padding:10px;
344345
}
345346
#termdocbox {
346347
position:absolute;
@@ -440,13 +441,16 @@ div.placeholder {
440441
background-color: #054D88;
441442
border-color: #02213A;
442443
}
444+
.gray {
445+
opacity: .5;
446+
}
443447
.form-control[disabled],
444448
.form-control[readonly],
445449
fieldset[disabled] .form-control,
446450
input[disabled] {
447451
cursor: not-allowed;
448452
background-color: #e6e6e6;
449-
opacity: 1;
453+
opacity: .5;
450454
}
451455
.navbar-default {
452456
background-color: #3A3A3A;

0 commit comments

Comments
 (0)