-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
2904 lines (2505 loc) · 144 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
source("global.r")
# Define UI for application that draws a histogram
ui <- fluidPage(
tags$html(class = "no-js", lang="en"),
tags$head(
tags$title('NARS Pop Est Tool| US EPA'),
tags$link(rel = "stylesheet", type = "text/css", href = "style.css"),
includeHTML("www/header.html")),
shinyjs::useShinyjs(),
# Application title
# Instructions ------------------------------------------------------------
navbarPage(title=span("NARS Population Estimate Calculation Tool (v. 2.3.0)",
style = "font-weight: bold; font-size: 24px"),
selected='instructions',position='static-top',
# Panel with instructions for using this tool
tabPanel(title='Instructions for Use',value='instructions',
h2("Overview"),
p('This Shiny app allows for calculation of population estimates as performed for
the National Aquatic Resource Surveys (NARS) and the plotting of results.
Estimates based on categorical and continuous variables are possible.
This app does not include all possible options but does allow typical settings
used by NARS for creating population estimates.'),
h3("Instructions for Use"),
bsCollapsePanel(title = h4(strong("Prepare Data for Analysis")),
tags$ol(
tags$li("Select data file and upload. If the data are to be loaded from a URL, check the
box to do so and paste or enter the URL for the file."),
tags$li("The variables in that file will populate dropdown lists on that tab."),
tags$li("Select variables to serve as site IDs, weights, response variables, and subpopulations
(if desired). If only overall or 'national' estimates are desired, check the box for overall analysis."),
tags$li("If data are to be used for change analysis, select the variable that distinguishes between design cycles (we usually assume this variable represents year)."),
tags$li(p("Select the type of variance you want to use. ",
strong("Local neighborhood variance"),
" uses a site's nearest neighbors to estimate variance, tending to
result in smaller variance values than variance based on a simple random sample. This approach is ",
em("recommended"),"and is the approach used in
NARS estimates. It requires site coordinates to be provided."),
tags$ul(
tags$li("For local neighborhood variance, select coordinate variables
(Albers projection, or some other projection)."),
tags$li("For simple random sample (SRS) variance, selecting a stratum variable
to better estimate variance is advised but not required. Coordinates are
not used with this type of variance."))),
br(),
tags$li("You may subset the data for analysis by up to one categorical variable. To do
this, select the check box to subset, then select the variable to subset by.
Finally, select one or more categories by which to subset data."),
tags$li("Click on the left hand button to view the full dataset if necessary."),
tags$li("Click on the right hand button above the data to subset the data before
proceeding to the analysis tabs.")
)),
bsCollapsePanel(title = h4(strong("Minimum Requirements for Analysis")),
tags$ul(
tags$li("The R package", strong("spsurvey, v.5.5 or later"),
"is required.
Be sure to update this package if an older version is
already installed." ),
tags$li("All variables must be contained in one file and include site IDs,
weights, response variables, subpopulations (if any), and optionally,
coordinates and/or design stratum (depending on type of variance desired)." ),
tags$li("All sites included in the dataset should have weight > 0. Any
records with a missing weight or a weight of 0 will be dropped
before analysis."),
tags$li("Input data should include",
strong("only one row per site and year/survey cycle"),
"(based on the variables for site ID and year/survey cycle selected). No within year revisits should be included, and all variables used in analysis should be separate columns in the dataset (i.e., wide format)."),
tags$li("Only delimited files, such as comma- and tab-delimited, are accepted for upload."),
tags$li("If local neighborhood variance is desired, coordinates must be
provided in some type of projection, such as Albers."),
tags$li("If variance based on a simple random sample is desired (or if
coordinates are not available), the design stratum should be provided
to better estimate variance."),
tags$li("If change or trend analysis is intended, all desired years of data must be
contained in one file, with a single variable that identifies
the individual years or survey cycles included.")
)),
bsCollapsePanel(title = h4(strong("Run Population Estimates")),
tags$ol(
tags$li("Select the type of analysis (categorical or continuous)."),
tags$li("Select the confidence level for estimating confidence intervals (90% or 95%).
The default is 95%."),
tags$li("If year or design cycle variable was selected on the Prepare Data for
Analysis tab, select year or cycle of interest."),
tags$li("For continuous analysis, select either CDFs (cumulative distribution
functions), percentiles, means, or totals."),
tags$li("Note that if data are missing for continuous variables,
those sites are ignored in analysis."),
tags$li("Click on the Run/Refresh Estimates button. Depending on the number of
responses, subpopulations, and type of analysis, it may take a few seconds
to several minutes."),
tags$li("If desired, download results, data used in analysis, and code to a zip file by clicking
the button labeled", strong("Save estimates, data, and code to a .zip file."))
),
tags$ol(strong("Outputs for categorical analysis:")),
tags$li("Type = Subpopulation group"),
tags$li("Subpopulation = Subpopulation name"),
tags$li("Indicator = Name of indicator"),
tags$li("Category = Category of indicator or Total"),
tags$li("nResp = Number of responses in category"),
tags$li("Estimate.P = Estimated percent of resource in category"),
tags$li("StdError.P = Estimated standard error of percent estimate"),
tags$li("MarginofError.P = Margin of error of percent estimate, representing difference between estimate and confidence bounds"),
tags$li("LCBXXPct.P = Lower confidence bound for percent, where XX represents the confidence level"),
tags$li("UCBXXPct.P = Upper confidence bound for percent, where XX represents the confidence level"),
tags$li("Estimate.U = Estimated amount of resource in category in same units as weights used"),
tags$li("StdError.U = Estimated standard error of amount of resource estimate"),
tags$li("MarginofError.U = Margin of error of amount of resource estimate, representing
difference between estimate and confidence bounds"),
tags$li("LCBXXPct.U = Lower confidence bound for amount of resource, where XX represents the
confidence level"),
tags$li("UCBXXPct.U = Upper confidence bound for amount of resource, where XX represents the
confidence level"),
br(),
tags$ol(strong("Outputs for continuous analysis:")),
tags$li("Type = Subpopulation group"),
tags$li("Subpopulation = Subpopulation name"),
tags$li("Indicator = Name of indicator"),
tags$li("Value = Value of indicator (CDF only)"),
tags$li("Statistic = Value of indicator (Percentiles only)"),
tags$li("nResp = Number of responses in category"),
tags$li("Estimate.P = Estimated percent of resource at or below value (CDF only)"),
tags$li("Estimate = Estimated value for given percentile (Percentiles only)"),
tags$li("StdError.P = Estimated standard error of percent estimate (CDF only)"),
tags$li("StdError = Estimated standard error of mean, variance, or standard deviation
estimate (Percentiles only)"),
tags$li("LCBXXPct.P = Lower confidence bound for percent, where XX represents the confidence level (CDF only)"),
tags$li("UCBXXPct.P = Upper confidence bound for percent, where XX represents the confidence level (CDF only"),
tags$li("LCBXXPct = Lower confidence bound for percentile estimate, where XX represents the
confidence level (Percentiles only)"),
tags$li("UCBXXPct = Upper confidence bound for percentile estimate, where XX represents the
confidence level (Percentiles only)"),
tags$li("Estimate.U = Estimated amount of resource at or below value in same units as weights
used (CDF only)"),
tags$li("StdError.U = Estimated standard error of amount of resource at or below estimate (CDF only)"),
tags$li("LCBXXPct.U = Lower confidence bound for amount of resource, where XX represents the
confidence level (CDF only)"),
tags$li("UCBXXPct.U = Upper confidence bound for amount of resource, where XX represents the
confidence level (CDF only)")
),
bsCollapsePanel(title = h4(strong("Run Change Analysis")),
tags$ol(
tags$li("First select the two years (or sets of years) to compare."),
tags$li("Select type of data to analyze (categorical or continuous)."),
tags$li("Select the confidence level for estimating confidence intervals (90% or 95%).
The default is 95%."),
tags$li("If continuous data are selected, select parameter on which to test
for differences (mean or median)."),
tags$li("Click on the Run/Refresh Estimates button. Depending on the number of
responses, subpopulations, and type of analysis, it may take a few
seconds to several minutes."),
tags$li("If any data are changed in the Prepare Data for Analysis tab, years
must be re-selected before running analysis."),
tags$li("To save outputs, including estimates, data used in analysis, and code, click the button labeled", strong("Save change estimates, data, and code as .zip file."))
),
tags$ul(strong("Outputs for Categorical Analysis:"),
tags$li("Survey_1 = Year or design cycle of first survey"),
tags$li("Survey_2 = Year or design cycle of second survey"),
tags$li("Type = Subpopulation group"),
tags$li("Subpopulation = Subpopulation name"),
tags$li("Indicator = Name of indicator"),
tags$li("Category = Category of indicator or Total"),
tags$li("DiffEst.P = Estimate of difference in percentage (Survey_2 - Survey_1)"),
tags$li("StdError.P = Estimated standard error of change percent estimate"),
tags$li("MarginofError.P = Margin of error of change percent estimate, representing
difference between estimate and confidence bounds"),
tags$li("LCBXXPct.P = Lower confidence bound for change percent, where XX represents
the confidence level"),
tags$li("UCBXXPct.P = Upper confidence bound for change percent, where XX represents
the confidence level"),
tags$li("DiffEst.U = Estimated amount of change in resource in category in same units
as weights used"),
tags$li("StdError.U = Estimated standard error of amount of change in resource estimate"),
tags$li("MarginofError.U = Margin of error of amount of change in resource estimate, representing
difference between estimate and confidence bounds"),
tags$li("LCBXXPct.U = Lower confidence bound for amount of change resource, where XX represents the
confidence level"),
tags$li("UCBXXPct.U = Upper confidence bound for amount of change resource, where XX represents the
confidence level"),
tags$li("nResp_1, nResp_2 = Number of responses in category in survey 1 and survey 2, respectively"),
tags$li("Estimate.P_1, Estimate.P_2 = Estimated percent of resource in category in survey 1
and survey 2, respectively"),
tags$li("StdError.P_1, StdError.P_2 = Estimated standard error of percent estimate in survey 1
and survey 2, respectively"),
tags$li("MarginofError.P_1, MarginofError.P_2 = Margin of error of percent estimate,
representing difference between estimate and confidence bounds in survey 1
and survey 2, respectively"),
tags$li("LCBXXPct.P_1, LCBXXPct.P_2 = Lower confidence bound for percent, where XX represents
the confidence level in survey 1 and survey 2, respectively"),
tags$li("UCBXXPct.P_1, UCBXXPct.P_2 = Upper confidence bound for percent, where XX represents
the confidence level in survey 1 and survey 2, respectively"),
tags$li("Estimate.U_1, Estimate.U_2 = Estimated amount of resource in category in same units
as weights used, in survey 1 and survey 2, respectively"),
tags$li("StdError.U_1, StdError.U_2 = Estimated standard error of amount of resource estimate
in survey 1 and survey 2, respectively"),
tags$li("MarginofError.U_1, MarginofError.U_2 = Margin of error of amount of resource estimate,
representing difference between estimate and confidence bounds in survey 1 and survey 2,
respectively"),
tags$li("LCBXXPct.U_1, LCBXXPct.U_2 = Lower confidence bound for amount of resource, where
XX represents the confidence level in survey 1 and survey 2, respectively"),
tags$li("UCBXXPct.U_1, UCBXXPct.U_2 = Upper confidence bound for amount of resource,
where XX represents the confidence level in survey 1 and survey 2, respectively")
),
tags$ul(strong("Outputs for Continuous Analysis (Means):"),
tags$li("Survey_1 = Year or design cycle of first survey"),
tags$li("Survey_2 = Year or design cycle of second survey"),
tags$li("Type = Subpopulation group"),
tags$li("Subpopulation = Subpopulation name"),
tags$li("Indicator = Name of indicator"),
tags$li("DiffEst = Estimate of difference in mean for indicator (Survey_2 - Survey_1)"),
tags$li("StdError = Estimated standard error of change estimate"),
tags$li("MarginofError = Margin of error of estimated mean, representing
difference between estimate and confidence bounds"),
tags$li("LCBXXPct = Lower confidence bound for estimated mean, where XX represents
the confidence level"),
tags$li("UCBXXPct = Upper confidence bound for estimated mean, where XX represents
the confidence level"),
tags$li("nResp_1, nResp_2 = Number of responses for indicator in survey 1 and survey 2, respectively"),
tags$li("Estimate_1, Estimate_2 = Estimated mean of resource for indicator in survey 1
and survey 2, respectively"),
tags$li("StdError_1, StdError_2 = Estimated standard error of estimated mean in survey 1
and survey 2, respectively"),
tags$li("MarginofError_1, MarginofError_2 = Margin of error of estimated mean,
representing difference between estimate and confidence bounds in survey 1
and survey 2, respectively"),
tags$li("LCBXXPct_1, LCBXXPct_2 = Lower confidence bound for indicator mean, where XX represents
the confidence level in survey 1 and survey 2, respectively"),
tags$li("UCBXXPct_1, UCBXXPct_2 = Upper confidence bound for indicator mean, where XX represents
the confidence level in survey 1 and survey 2, respectively"),
),
tags$ul(strong("Outputs for Continuous Analysis (Medians):"),
tags$li("All of the output variable names match those for Categorical Change Analysis (see above)"),
tags$li("The two categories for this output are Greater_Than_Median and Less_Than_Median,
but the interpretations are the same")
)),
bsCollapsePanel(title = h4(strong("Run Trend Analysis")),
tags$ol(
tags$li("Trend analysis runs on only categorical response variables, using options selected on data preparation tab."),
tags$li("Trend will be run using all years in the dataset."),
tags$li("If a response is missing for all observations in a particular year, that year will be excluded from the analysis of that response and a warning will be displayed."),
tags$li("The confidence level for trend analysis is set at 95%."),
tags$li("Click on the Run/Refresh Estimates button. Depending on the number of
responses and subpopulations, it may take a few seconds to several minutes to run."),
tags$li("To save outputs, including estimates, data used in analysis, code, and sample sizes by year and response variable, click the button labeled", strong("Save trend results, data, code, and sample sizes as .zip file."))
),
tags$ul(strong("Outputs for Categorical Trend Analysis:"),
tags$li("Survey_1 = Year or design cycle of first survey"),
tags$li("Survey_2 = Year or design cycle of second survey"),
tags$li("Type = Subpopulation group"),
tags$li("Subpopulation = Subpopulation name"),
tags$li("Indicator = Name of indicator or response variable"),
tags$li("Category = Category of indicator"),
tags$li("Trend_Estimate = estimate of trend slope"),
tags$li("Trend_Std_Error = standard error of trend slope"),
tags$li("Trend_LCB95Pct = lower 95% confidence bound of trend slope"),
tags$li("Trend_UCB95Pct = upper 95% confidence bound of trend slope"),
tags$li("Trend_p_Value = p-value for trend slope"),
tags$li("Intercept_Estimate = estimate of trend intercept"),
tags$li("Intercept_Std_Error = standard error of trend intercept"),
tags$li("Intercept_LCB95Pct = lower 95% confidence bound of trend intercept"),
tags$li("Intercept_UCB95Pct = upper 95% confidence bound of trend intercept"),
tags$li("Intercept_p_Value = p-value for trend intercept"),
tags$li("R_Squared = R-squared for trend"),
tags$li("Adj_R_Squared = Adjusted R-squared for trend"))
),
bsCollapsePanel(title = h4(strong("Plot Categorical Estimates")),
tags$ol(
tags$li("Either run population estimates on categorical data either within the
app or import results into the app."),
tags$li("Variables in dataset must match those expected as output from
spsurvey::cat_analysis function:", strong("Type, Subpopulation, Indicator,
Category, Estimate.P, StdError.P, LCBXXPct.P, UCBXXPct.P, Estimate.U,
StdError.U, LCBXXPct.U, UCBXXPct.U, where XX represents the confidence
level.")),
tags$li("Select either proportion or unit estimates to plot from Estimate Type."),
tags$li("Select Category values that represent Good, Fair, Poor, Not Assessed,
and Other condition classes. More than one value per condition class
in the dataset may be selected. For example, if one response uses
Good/Fair/Poor and another used At or Below Benchmark/Above Benchmark,
both Good and At or Below Benchmark can be selected."),
tags$li(strong("Optional:"), "add plot title and define resource type/unit
(i.e., stream length, number of lakes, coastal or wetland area)"),
tags$li("Click the Plot/Refresh Button to create plots."),
tags$li("From the menus on the right-hand side of the page, select the
Indicator of interest, and then the Subpopulation Group. Then
select the Subpopulation of interest. The upper plot shows the
individual subpopulation and the lower plot show a particular
condition class across all subpopulations."),
tags$li("To show confidence bound values, click the box above the main
and/or subpopulation plots."),
tags$li("The default order of the subpopulations in the lower plot is
alphabetical, but to sort by the estimate of the", em("Good"),
"class,
click the box for", em("Sort Subpopulations by Good Condition"),"."),
tags$li("Select", em("Download Estimate Plot"), "or",
em("Download Subpopulation Plot"), "to
save a .png file of the output. ")
)),
bsCollapsePanel(title = h4(strong("Plot Continuous Estimates")),
tags$ol(
tags$li("Either run population estimates on continuous data to obtain
CDF estimates within the app, or import results into the app."),
tags$li("Variables in dataset must match those expected as output from
spsurvey::cont_analysis function:", strong("Type, Subpopulation, Indicator,
Value, Estimate.P, StdError.P, LCBXXPct.P, UCBXXPct.P, Estimate.U,
StdError.U, LCBXXPct.U, UCBXXPct.U, where XX represents the confidence level.")),
tags$li("Select either proportion or unit estimates to plot
from Estimate Type."),
tags$li(strong("Optional:"), "Add plot title, indicator units,
and define resource type/unit."),
tags$li("Click the Plot Continuous Estimates button."),
tags$li("Select indicator from dropdown, then select a subpopulation group. Add
or remove subpopulations to the plot from the",
em("Add/Remove Subpopulations"),
"dropdown."),
tags$li(strong("Optional:"), "Add an Indicator Threshold, add confidence bands, and/or
change the x-axis to log10 scale. Be aware that if you have values
that are below or equal to zero, points will be excluded from the
plot if the", em("Log Scale X-Axis"), "option is selected.")
)),
br(),
p('Contact Karen Blocksom at [email protected] with questions or feedback.'),
h3('Disclaimer'),
p('The United States Environmental Protection Agency (EPA) GitHub project code is provided
on an "as is" basis and the user assumes responsibility for its use. EPA has relinquished
control of the information and no longer has responsibility to protect the integrity,
confidentiality, or availability of the information. Any reference to specific commercial
products, processes, or services by service mark, trademark, manufacturer, or otherwise,
does not constitute or imply their endorsement, recommendation or favoring by EPA. The EPA
seal and logo shall not be used in any manner to imply endorsement of any commercial product
or activity by EPA or the United States Government.')),
# Prepare Data ------------------------------------------------------------
# Panel to import and select data to analyze
tabPanel(title='Prepare Data for Analysis',value="prepdata",
fluidRow(
# Input: Select a file ---
column(3,
add_busy_spinner(spin='fading-circle', position='full-page'),
checkboxInput("websource", 'Input file from URL instead of local directory', FALSE),
# Read in file from local computer
conditionalPanel(condition="input.websource == false",
fileInput(inputId='file1', buttonLabel='Browse...',
label='Select a delimited file for analysis',
multiple=FALSE, accept=c('text/csv','text/comma-separated-values,text/plain','.csv')
)),
# Read in file from website URL - need to add a button to signal it should start uploading
conditionalPanel(condition="input.websource == true",
textInput("urlfile", "Paste or enter full URL here."),
actionButton("urlbtn", "Load file from URL")),
# Horizontal line ----
tags$hr(),
# Input: checkbox if file has header, default to TRUE ----
checkboxInput('header','Header',TRUE),
# Input: Select delimiter ----
radioButtons("sep","Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),
# Horizontal line
tags$hr(),
# Input: Select number of rows to display
radioButtons("disp","Display",
choices = c(Head = 'head',
All = 'all'),
selected='head'),
checkboxInput("subcheck","Subset data using a single categorical variable", FALSE),
conditionalPanel(condition="input.subcheck == true",
selectizeInput('subvar', "Select variable to use for subsetting", choices=NULL, multiple=FALSE),
selectizeInput("subcat","Select one or more categories by which to subset data", choices=NULL,
multiple=TRUE))),
# Provide dropdown menus to allow user to select site, weight, and response variables from those in the imported dataset
column(3,
shiny::selectizeInput("siteVar", label="Select site variable",
choices=NULL, multiple=FALSE) %>%
helper(type = "inline", icon = 'exclamation', colour='#B72E16',
title = "Site variable selection",
content = paste("Select a site variable. If multiple years and resampled
sites are included in the dataset, be sure the site
variable has the same value across years."),
size = "s", easyClose = TRUE, fade = TRUE),
selectizeInput("weightVar","Select weight variable", choices=NULL, multiple=FALSE),
selectizeInput("respVar","Select up to 10 response variables - must all be either categorical or numeric",
choices=NULL, multiple=TRUE),
checkboxInput('chboxYear', 'Check box if performing change analysis or need to subset data by year
or cycle for population estimates'),
conditionalPanel(condition="input.chboxYear == true",
selectizeInput("yearVar","Select year variable",
choices=NULL, multiple=FALSE)),
checkboxInput('natpop','Calculate overall (all sites) estimates?', TRUE),
checkboxInput('subpop', 'Calculate estimates for subpopulations?', FALSE),
# If national estimates box is NOT checked, show subpopulation dropdown list
conditionalPanel(condition = 'input.subpop == true',
selectizeInput("subpopVar","Select up to 10 subpopulation variables",
choices=NULL, multiple=TRUE)),
h5(p(strong("If ANY changes have been made to your choices, you MUST click the button to prepare data for analysis again!"), style="color:#B72E16"))
),
# Set up type of variance to use in estimates: local or SRS
column(3,
radioButtons('locvar',"Type of variance estimate to use (select one)",
choices = c('Local neighborhood variance (recommended, used for NARS,
requires site coordinates)' = 'local',
'Simple Random Sample (requires stratum but not site
coordinates)' = 'SRS'),
select = 'local'),
# If local, user must select x and y coordinates and convert to Albers if in lat/long
conditionalPanel(condition = "input.locvar == 'local'",
selectizeInput("coordxVar","Select the X coordinate variable
(required only for local neighborhood variance)",
choices=NULL, multiple=FALSE, selected=NULL),
selectizeInput("coordyVar","Select the Y coordinate variable
(required only for local neighborhood variance)",
choices=NULL, multiple=FALSE, selected=NULL)
),
# Select stratum if Simple Random Sample
selectizeInput("stratumVar","Select a categorical stratum variable if desired. May be used for either variance type.",
choices=NULL, multiple=FALSE)
)
),
# Press button to subset data for analysis - must click here first
column(4, actionButton("resetBtn", "Click to revert back to full dataset or change data display")),
column(4, actionButton("subsetBtn", strong("Click HERE to prepare data for analysis"), style="color:#B72E16"), offset=2),
hr(),
br(),
# Show a table of the data
h4("Data for Analysis"),
DT::dataTableOutput("contents")
),
# Run Population Estimates ------------------------------------------------
# Tab to run population estimates
tabPanel(title="Run Population Estimates",value="runest",
fluidRow(
column(3,
# add_busy_bar(color="red", centered=TRUE),
# User must select categorical or continuous variable analysis, depending on response variables selected
radioButtons("atype","Type of Analysis (pick one)",
choices = c('Categorical (for character variables)' = 'categ',
'Continuous (for numeric variables)' = 'contin'),
selected='categ'),
# If continuous analysis selected, select whether CDFs or percentiles are desired.
conditionalPanel(condition = "input.atype == 'contin'",
radioButtons("cdf_pct", "Show CDF, percentile, mean, or total results",
choices = c(CDF = 'cdf', Percentiles = 'pct', Means = 'mean', Totals = 'total'),
selected = 'pct')),
conditionalPanel(condition="input.chboxYear==true",
selectizeInput('selYear', 'Select the year for analysis',
choices=NULL, multiple=FALSE)),
radioButtons('ciSize', 'Confidence level',
choices = c('90%' = '90', '95%' = '95'),
selected = '95'),
p("If the", strong("Run/Refresh Estimates"), "button is grayed out, return to the",
strong("Prepare Data for Analysis"), "tab and click the button that says",
strong("Click HERE to prepare data for analysis")),
p("Note that if all values are very small, the results may appear as zeroes. Save
and view output file to see the results with full digits."),
# Once data are prepared, user needs to click to run estimates, or rerun estimates on refreshed data
shinyjs::disabled(actionButton('runBtn', "Run/Refresh estimates")),
hr(),
# Click to download results into a comma-delimited file
shinyjs::disabled(downloadButton("dwnldcsv","Save estimates, data, and code to a .zip file"))),
# Show results here
column(8,
h4("If output is not as expected, be sure you chose the correct ",
strong("Type of Analysis"), "(Categorical or Continuous) for your data",
style="color:#225D9D"),
h4("Warnings"),
DT::dataTableOutput("warnest"),
br(),
br(),
h4("Analysis Output"),
DT::dataTableOutput("popest")
)
)
),
# Run Change Analysis -----------------------------------------------------
tabPanel(title="Run Change Analysis", value='change',
fluidRow(
h4(" ", "If a different set of response variables from those
used in the population estimates is desired,
return to the", strong("Prepare Data for Analysis"),
"tab to re-select variables. Then click the button to
prepare data for analysis again.",
style="color:#225D9D"),
column(3,
# User must select years to compare
selectizeInput('chgYear1',"Select two years of data to compare in desired order",
choices=NULL, multiple=TRUE),
radioButtons("chgCatCont", "Type of variables to analyze",
choices = c(Categorical = 'chgCat', Continuous = 'chgCont'),
select = 'chgCat'),
conditionalPanel(condition = "input.chgCatCont == 'chgCont'",
radioButtons("testType", "Base test on mean or median",
choices = c(Mean='mean', Median='median'),
selected = 'mean')),
radioButtons('ciSize_chg', 'Confidence level',
choices = c('90%' = '90', '95%' = '95'),
selected = '95'),
# Once data are prepared, user needs to click to run estimates, or rerun estimates on refreshed data
hr(),
p("If the", strong("Run/Refresh Estimates"), "button is grayed out, return to the",
strong("Prepare Data for Analysis"), "tab and click the button that says",
strong("Click HERE to prepare data for analysis")),
shinyjs::disabled(actionButton('chgBtn', "Run/Refresh estimates")),
hr(),
# Click to download results into a comma-delimited file
shinyjs::disabled(downloadButton("chgcsv","Save change estimates, data, and code as .zip file"))),
column(8,
h4("Warnings"),
DT::dataTableOutput("warnchg"),
br(),
br(),
h4("Change Analysis Output"),
DT::dataTableOutput("changes")
)
)
),
# Trend Analysis ------------------------------
tabPanel(title="Run Trend Analysis", value='trend',
fluidRow(
h3("Use for categorical analysis only - Please note:"),
tags$ul(
tags$li("This is only designed for analysis of categorical
variables and may convert any numerical variable to categorical.
Any subsetting of data to align different years or cycles
must be done either on the", strong("Prepare Data for Analysis"),
"tab or before importing the dataset."),
br(),
tags$li("If a different set of
response variables from those
used in the population or change estimates is desired,
return to the", strong("Prepare Data for Analysis"),
"tab to re-select variables. Then click the button to
prepare data for analysis again."),
br(),
tags$li("If the", strong("Run/Refresh Estimates"), "button is grayed out, return to the",
strong("Prepare Data for Analysis"), "tab and click the button that says",
strong("Click HERE to prepare data for analysis"))
),
column(3,
# Once data are prepared, user needs to click to run estimates, or rerun estimates on refreshed data
shinyjs::disabled(actionButton('trendBtn', "Run/Refresh estimates")),
hr(),
# Click to download results into a comma-delimited file
shinyjs::disabled(downloadButton("trendcsv","Save trend results, data, code, and sample sizes as .zip file"))),
column(8,
h4("Warnings"),
DT::dataTableOutput("warntrend"),
h4("Trend Analysis Output"),
DT::dataTableOutput("trends")
)
)
),
# Plot Data ---------------------------------------------------------------
####Categorical Plot UI####
tabPanel(title="Plot Categorical Estimates",
fluidRow(
sidebarPanel(
radioButtons(inputId="catinput",
label=strong("Choose Categorical Estimate Dataset to Use:"),
choices=c("Upload Estimate Data File", "Current Estimate Data"),
selected = "Upload Estimate Data File",
inline=FALSE),
uiOutput("catui"),
selectInput(inputId = "Estimate",
label = HTML("<b>Select Estimate Type</b>"),
choices = c("Proportion Estimates" = "P Estimates", "Unit Estimates" = "U Estimates"),
multiple = FALSE,
width = "300px") %>%
#Estimate Type helper
helper(type = "inline",
icon = 'circle-question',
title = "Estimate Type",
content = c("<b>Proportion Estimates:</b> Proportion of observations that
belong to each level of the categorical variable.",
"<b>Unit Estimates:</b> Total units (i.e. extent) that belong
to each level of the categorical variable (total number
(point resources), total line length (linear network), or
total area (areal network))."),
size = "s", easyClose = TRUE, fade = TRUE),
tags$style(HTML(".shiny-output-error-validation {color: #ff0000; font-weight: bold;}")),
selectInput(inputId = "Good",
label = HTML("<b>Select <span style='color: #5796d1'>'Good'</span> Condition Classes</b>"),
choices = "",
selected = NULL,
multiple = TRUE,
width = "300px") %>%
#Condition Category helper
helper(type = "inline", icon = 'circle-question',
title = "Condition Category Color",
content = paste("The following inputs ask you to define the condition classes
which will be used in the plots. You may use the same
category for multiple conditions.", strong(em("For example, if
your dataset
contains some responses for which Good is the best condition
and some for which Low is the best, you can select both for
plotting. Only those applicable to a given response will be
shown in the plot."))),
size = "s", easyClose = TRUE, fade = TRUE),
selectInput(inputId = "Fair",
label = HTML("<b>Select <span style='color: #EE9A00'>'Fair'</span> Condition Classes</b>"),
choices = "",
selected = NULL,
multiple = TRUE,
width = "300px"),
selectInput(inputId = "Poor",
label = HTML("<b>Select <span style='color: #f55b5b'>'Poor'</span> Condition Classes</b>"),
choices = "",
selected = NULL,
multiple = TRUE,
width = "300px"),
selectInput(inputId = "Not_Assessed",
label = HTML("<b>Select <span style='color: #c77505'>'Not Assessed'</span> Condition Classes</b>"),
choices = "",
selected = NULL,
multiple = TRUE,
width = "300px"),
selectInput(inputId = "Other",
label = HTML("<b>Select <span style='color: #d15fee'>'Other'</span> Condition Classes</b>"),
choices = "",
selected = NULL,
multiple = TRUE,
width = "300px"),
textInput("title", "Add a Plot Title", value = "", width = "300px", placeholder = "Optional"),
textInput("resource", "Define Resource Type/Unit", value = "",
width = "300px", placeholder = "Resource") %>%
#Resource Type helper
helper(type = "inline", icon = 'circle-question',
title = "Resource Type",
content = c("This input defines the plot axis label. Resource Type is
the resource evaluated in your design (e.g., Stream Miles,
Wetland Area, Coastal Area, Lakes)."),
size = "s", easyClose = TRUE, fade = TRUE),
actionButton("plotbtn", strong("Plot/Refresh Estimates"), icon=icon("chart-bar")),
br(),br(),
width = 3),
mainPanel(
conditionalPanel(condition="input.plotbtn",
column(3,
tags$head(tags$style(HTML("#Ind_Plot ~ .selectize-control.single .selectize-input {background-color: #FFD133;}"))),
selectInput(inputId = "Ind_Plot",
label = HTML("<b>Select Indicator</b>"),
choices = "",
multiple = FALSE,
width = "200px") %>%
#Indicator input helper
helper(type = "inline",
icon = 'circle-question',
title = "Indicator",
content = c("Select the indicator to display
categorical estimates by population."),
size = "s", easyClose = TRUE, fade = TRUE),
#column(3,
tags$head(tags$style(HTML("#Type_Plot ~ .selectize-control.single .selectize-input {background-color: #FFD133;}"))),
selectInput(inputId = "Type_Plot",
label = HTML("<b>Select Subpopulation Group</b>"),
choices = NULL,
multiple = FALSE,
width = "200px") %>%
#Subpop Group input helper
helper(type = "inline",
icon = 'circle-question',
title = "Subpopulation Group",
content = c("Select the Subpopulation group
to generate individual subpopulation
estimates and to use in the subpopulation
comparison plot."),
size = "s", easyClose = TRUE, fade = TRUE))),
column(8, offset = 2,
h3(strong(HTML("<center>Categorical Estimates by Population<center/>") %>%
#Condition estimate helper
helper(type = "inline",
icon = 'circle-question',
title = "Categorical Estimates",
content = c("Cycle through populations to display
categorical estimates and download the plot,
if desired."),
size = "s", easyClose = TRUE, fade = TRUE)))),
fluidRow(
column(3, offset=1,
conditionalPanel(condition="input.plotbtn",
selectInput(inputId = "Tot_Pop",
label = HTML("<b>Select Subpopulation</b>"),
choices = NULL,
selected = NULL,
multiple = FALSE))),
column(3, offset=1,
conditionalPanel(condition="input.plotbtn",
checkboxInput(inputId = "indconlim",
label= "Add Confidence Limit Values",
value = FALSE,
width = NULL)))),
fluidRow(
column(3, offset = 1,
conditionalPanel(condition="input.plotbtn",
downloadButton("downloadPlot1", "Download Estimate Plot")))),
plotOutput("plot", width = "75%", height = "300px"),
br(), br(), br(),
column(8, offset = 2,
h3(strong(HTML("<center>Subpopulation Comparison<center/>") %>%
#Subpopulation helper
helper(type = "inline",
icon = 'circle-question',
title = "Subpopulation Comparison",
content = c("Cycle through population groups to compare categorical estimates by condition and download plot, if desired. If there are no subpopulations, no subpopulation plots will appear."),
size = "s", easyClose = TRUE, fade = TRUE)))),
fluidRow(
column(3, offset=1,
conditionalPanel(condition="input.plotbtn",
# tags$head(tags$style(HTML("#Con_Plot ~ .selectize-control.single .selectize-input {border: 1px solid #33ACFF;}"))),
selectInput(inputId = "Con_Plot",
label = HTML("<b>Select Condition</b>"),
choices = "",
multiple = FALSE))),
column(3, offset=1,
conditionalPanel(condition="input.plotbtn",
checkboxInput(inputId = "goodsort",
label= HTML("Sort Subpopulations by <span style='color: #5796d1'>'Good'</span> Condition"),
value = FALSE,
width = NULL),
checkboxInput(inputId = "subconlim",
label= "Add Confidence Limit Values",
value = FALSE,
width = NULL)))),
fluidRow(
column(3, offset=1,
conditionalPanel(condition="input.plotbtn",
downloadButton('downloadPlot2', "Download Subpopulation Plot")))),
plotOutput("plot2", width = "75%"))
)),
####Continuous Plot UI####
tabPanel(title="Plot Continuous Estimates",
sidebarPanel(
radioButtons(inputId="coninput",
label=strong("Choose Cumulative Distribution Function (CDF) Estimate Dataset to Use:"),
choices=c("Upload Estimate Data File", "Current Estimate Data"),
selected = "Upload Estimate Data File",
inline=FALSE),
uiOutput("conui"),
selectInput(inputId = "Estimate_CDF",
label = HTML("<b>Select Estimate Type</b>"),
choices = c("Proportion Estimates" = "P Estimates_CDF", "Unit Estimates" = "U Estimates_CDF"),
multiple = FALSE,
width = "300px") %>%
#Estimate Type helper
helper(type = "inline",
icon = 'circle-question',
title = "Estimate Type",
content = c("<b>Proportion Estimates:</b> Proportion of
observations that belong to each level of the
categorical variable.",
"<b>Unit Estimates:</b> Total units (i.e. extent)
that belong to each level of the categorical
variable (total number (point resources), total
line length (linear network), or total area
(areal network))."),
size = "s", easyClose = TRUE, fade = TRUE),
textInput("title2", "Add a Plot Title", value = "", width = "300px", placeholder = "Optional"),
textInput("units", "Add Indicator Units", value = "", width = "300px", placeholder = "Optional"),
textInput("resource2", "Define Resource Type/Unit", value = "", width = "300px", placeholder = "Resource") %>%
#Resource Type helper
helper(type = "inline",
icon = 'circle-question',
title = "Resource Type",
content = c("This input defines the plot axis label. Resource
Type is the resource evaluated in your design
(e.g., Stream Miles, Wetland Area, Coastline)."),
size = "s", easyClose = TRUE, fade = TRUE),
actionButton("plotbtncon", strong("Plot Continuous Estimates"), icon=icon("chart-bar"))
,width=4),#sidebarPanel
mainPanel(
column(3, offset=1,
conditionalPanel(condition="input.plotbtncon",
selectInput(inputId = "Ind_Con",
label = HTML("<b>Select Indicator</b>"),
choices = "",
multiple = FALSE)),
conditionalPanel(condition="input.plotbtncon",
selectInput(inputId = "Pop_Con",
label = HTML("<b>Select Population</b>"),
choices = "",
multiple = FALSE)),
conditionalPanel(condition="input.plotbtncon",
selectInput(inputId = "SubPop_Con",
label = HTML("<b>Add/Remove Subpopulations</b>"),
choices = "",
multiple = TRUE))),
fluidRow(
column(3, offset=1,
conditionalPanel(condition="input.plotbtncon",
numericInput("Thresh", "Indicator Threshold (optional)",
value = NULL),
checkboxInput(inputId = "conflim",
label="Add Confidence Limits",
value = FALSE,
width = NULL),
checkboxInput(inputId = "log",
label="Log Scale X-Axis",
value = FALSE,
width = NULL)))),
column(8, offset = 2,
h3(strong(HTML("<center>CDF Estimates<center/>") %>%
#CDF helper
helper(type = "inline",
icon = 'circle-question',
title = "Cumulative Distribution Function (CDF)",
content = c("A Cumulative Distribution Function calculates
the cumulative probability for a given value and
can be used to determine the probability that a
random observation that is taken from the
population will be less than or equal to a certain
value."),
size = "s", easyClose = TRUE, fade = TRUE))),
hr(),
h4("NOTE: Plotting and downloading may take a while if there are multiple
subpopulations. PLEASE BE PATIENT.")),
fluidRow(
column(3,
conditionalPanel(condition="input.plotbtncon",
downloadButton("download1", "Download CDF Plot")))),
plotOutput("CDFsubplot", width = "75%"),
br(), br(), br(),
column(8, offset = 2,
h3(strong(HTML("<center>Distribution of Estimates by Population<center/>") %>%
#CDF helper
helper(type = "inline",
icon = 'circle-question',
title = "Ridgeline Distribution Plot",
content = c("A <b>Ridgeline Plot</b>, also known as a Joy Plot,
is used to visualize distributions of several groups.
Each group produces a density curve which overlaps
with each other to help visualize differences.",
"",
"Small vertical lines represent values.",
"Large vertical lines represent quartiles."),
size = "s", easyClose = TRUE, fade = TRUE)))),
fluidRow(
column(3,
conditionalPanel(condition="input.plotbtncon",
downloadButton("download2", "Download Distribution Plot")))),
br(),
plotOutput("Distplot", width = "75%")
))
),
# Site Footer ----
includeHTML("www/footer.html")) # END fluidPage
# Begin Server ----
server <- function(input, output, session) {
observe_helpers()
# Read in Data for Preparation --------------------------------------------
# Read in data file as selected
dataIn <- reactive({
if(input$websource==FALSE){
file1 <- input$file1
req(file1)
df <- read.table(input$file1$datapath,
header = input$header,
sep = input$sep,
stringsAsFactors=F)
}else{
if(input$urlbtn>0){
df <- read.table(url(input$urlfile),
header = input$header,
sep = input$sep,
stringsAsFactors=F)
}
}
df
})
# Need code to show initial version of dataIn() before subsetting or pressing the button to reset
observeEvent(input$subsetBtn, {
shinyjs::disable('dwnldcsv')
shinyjs::enable('chgBtn')
shinyjs::enable('runBtn')
shinyjs::disable('chgcsv')
shinyjs::enable('trendBtn')
shinyjs::disable('trendcsv')
if(input$disp == 'head'){
output$contents <- DT::renderDataTable({head(dataOut())}, options = list(digits=5, rownames=F,
scrollX=TRUE, scrollY=TRUE))
}else{
output$contents <- DT::renderDataTable({dataOut()}, options = list(digits=5, rownames=F,
scrollX=TRUE, scrollY=TRUE))
}
})
observeEvent(input$resetBtn, {
if(input$disp == 'head'){
output$contents <- DT::renderDataTable({head(dataIn())},
options = list(digits=5, rownames=F,
scrollX=TRUE, scrollY=TRUE))
}else{
output$contents <- DT::renderDataTable({dataIn()}, options = list(digits=5, rownames=F,
scrollX=TRUE, scrollY=TRUE))
}
})
# Use current dataset to refresh dropdown list of variables.
observe({
vars <- colnames(dataIn())
updateSelectizeInput(session, "weightVar", "Select weight variable", choices=vars)
updateSelectizeInput(session, 'respVar', 'Select up to 10 response variables - All must be either categorical or numeric',
choices=vars, selected = NULL,
options = list(maxItems=10))
updateSelectizeInput(session, 'coordxVar', "Select the X coordinate variable \n(required only
for local neighborhood variance)",
choices=vars, selected = NULL)
updateSelectizeInput(session, 'coordyVar', "Select the Y coordinate variable\n(required only
for local neighborhood variance)",
choices=vars, selected = NULL)
updateSelectizeInput(session, 'siteVar', 'Select site variable', choices=vars)
updateSelectizeInput(session, 'subpopVar', 'Select up to 10 subpopulation variables \n(required if not
national estimates only)', choices=vars, selected=NULL,
options = list(maxItems=10))
updateSelectizeInput(session, "stratumVar", "Select a categorical stratum variable if desired. May be used for either variance type.",
choices=c('None', vars), selected='None')
updateSelectizeInput(session, "yearVar","Select year variable",
choices=c('', vars))
updateSelectizeInput(session, "subvar", choices=vars)
updateSelectizeInput(session, 'szwtVar', choices=vars)
})
observeEvent(input$subvar,{
catchoices <- as.character(sort(unique(dataIn()[[input$subvar]])))
updateSelectizeInput(session, 'subcat', choices = catchoices, selected=NULL, server=TRUE)
})
# After Prepare Data for Analysis Button Clicked --------------------------
# Once subset button is clicked, validate selections to make sure any variable only occurs in set of selections
dataOut <- eventReactive(input$subsetBtn,{
if(input$subsetBtn > 0){
if(input$chboxYear==TRUE){