library(shiny)

shinyUI(pageWithSidebar(
                        headerPanel("RAPPOR Simulation"),
                        sidebarPanel(
                                     tabsetPanel(
                                                 tabPanel("RAPPOR",
                                                          selectInput("size", "Bloom filter size:",
                                                                      c(4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096),
                                                                      selected = 128),
                                                          selectInput("hashes", "Number of hash functions:",
                                                                      c(1, 2, 4, 8, 16, 32),
                                                                      selected = 2),
                                                          selectInput("instances", "Number of cohorts:",
                                                                      c(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024),
                                                                      selected = 8),
                                                          br(),
                                                          br(),
                                                          sliderInput("N", "Number of samples to generate:",
                                                                      min = 100000, max = 10000000,
                                                                      value = 1000000, step = 100000),
                                                          br(),
                                                          helpText(actionButton("sample", "Rerun Simulations"), align = "center"),
                                                          br(),
                                                          br(),
                                                          helpText("Version 0.1", align = "center"),
                                                          helpText(a("RAPPOR Repository", href="http://github.com/google/rappor"), align = "center")),
                                                 tabPanel("Privacy",
                                                          sliderInput("p", "Probability of reporting noise (p):",
                                                                      min = .01, max = .99, value = .5, step = .01),
                                                          sliderInput("q", "Probability of reporting signal (q):",
                                                                      min = .01, max = .99, value = .75, step = .01),
                                                          sliderInput("f", "Probability of lies (f):",
                                                                      min = 0, max = .99, value = .5, step = .01),
                                                          br(),
                                                          htmlOutput("epsilon"),
                                                          br(),
                                                          helpText("* In addition to p, q and f, the number of hash functions (set in the RAPPOR tab) also effects privacy guarantees."),
                                                          br(),
                                                          br(),
                                                          br()
                                                          ),
                                                 tabPanel("Population",
                                                          sliderInput("nstrs", "Number of strings:",
                                                                      min = 100, max = 10000, value = 300, step = 100),
                                                          br(),
                                                          sliderInput("nonzero", "Proportion of non-zero strings:",
                                                                      min = .1, max = 1, value = 0.5, step = .1),
                                                          br(),
                                                          selectInput("decay", "Decay of non-zero strings",
                                                                      c("Linear", "Exponential", "Constant"),
                                                                      selected = "Exponential"),
                                                          br(),
                                                          conditionalPanel(condition = "input.decay == 'Exponential'",
                                                                           sliderInput("expo", "Rate of exponential decay",
                                                                                       min = 1, max = 200, value = 10, step = 1)),
                                                          sliderInput("background", "Frequency of background strings:",
                                                                      min = 0, max = .2, value = .05, step = .01),
                                                          br(),
                                                          br(),
                                                          br()
                                                 ),
                                                 tabPanel("Decoding",
                                                          sliderInput("alpha", "Alpha - probability of false positive:",
                                                                      min = .01, max = .3, value = .05, step = .01),
                                                          br(),
                                                          selectInput("correction", "Multiple testing correction",
                                                                      c("None", "Bonferroni", "FDR"),
                                                                      selected = "FDR"),
                                                          br(),
                                                          sliderInput("missing", "Proportion of non-zero strings missing from decoding:",
                                                                      min = 0, max = 1, value = 0, step = .1),
                                                          br()
                                                          )
                                     )),
                        mainPanel(
                                  tabsetPanel(
                                              tabPanel("Life of a  Report",
                                                       actionButton("new_user", "New Participant"),
                                                       actionButton("new_value", "New Value"),
                                                       actionButton("new_report", "New Report"),
                                                       plotOutput("example", height = "600px")),
                                              tabPanel("Population", plotOutput("probs", height = "600px")),
                                              tabPanel("Results", helpText(h3("Summary")), htmlOutput("pr"), br(), br(), dataTableOutput("tab")),
                                              tabPanel("True Bits", plotOutput("truth", height = "800px")),
                                              tabPanel("Estimated Bits", plotOutput("ests", height = "800px")),
                                              tabPanel("Estimates vs Truth", plotOutput("ests_truth", height = "600px")),
                                              # tabPanel("Lasso", plotOutput("lasso", height = "600px")),
                                              tabPanel("Residuals", plotOutput("resid", height = "600px"))
                                              )
                                  )
                        ))
