-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.R
129 lines (102 loc) · 4.12 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
library(shiny)
library(clinfun)
source("BayesMultiStage.R")
# Define UI for dataset viewer app ----
ui <- fluidPage(
# App title ----
titlePanel("More Widgets"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Select a dataset ----
# selectInput("dataset", "Choose a dataset:",
# choices = c("rock", "pressure", "cars")),
# Input: Specify the number of observations to view ----
numericInput("alpha", "Type I error rate, α (one-sided):", 0.05, step = 0.01),
numericInput("power", "Power:", 0.8, step = 0.01),
numericInput("p0", "Response probability of poor drug, p0:", 0.05, step = 0.01),
numericInput("p1", "Response probability of good drug, p1:", 0.15, step = 0.01),
# Include clarifying text ----
helpText("Note: while the data view will show only the specified",
"number of observations, the summary will still be based",
"on the full dataset."),
# Input: actionButton() to defer the rendering of output ----
# until the user explicitly clicks the button (rather than
# doing it immediately when inputs change). This is useful if
# the computations required to render output are inordinately
# time-consuming.
actionButton("update", "Update View")
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Header + summary of distribution ----
h4("Summary"),
verbatimTextOutput("summary"),
# Output: Header + table of distribution ----
h4("Observations"),
tableOutput("view"),
plotOutput("distPlot")
)
)
)
# Define server logic to summarize and view selected dataset ----
server <- function(input, output) {
# Return the requested dataset ----
# Note that we use eventReactive() here, which depends on
# input$update (the action button), so that the output is only
# updated when the user clicks the button
# datasetInput <- eventReactive(input$update, {
# switch(input$dataset,
# "rock" = rock,
# "pressure" = pressure,
# "cars" = cars)
# }, ignoreNULL = FALSE)
datasetInput <- eventReactive(input$update, {
# list(pu = input$p0, pa = input$p1, ep1 = input$alpha, ep2 = 1-input$power)
# Sys.sleep(10)
ph2simon(pu = input$p0, pa = input$p1, ep1 = input$alpha, ep2 = 1-input$power)
}, ignoreNULL = T)
# Generate a summary of the dataset ----
output$summary <- renderPrint({
# dataset <- datasetInput()
# summary(dataset)
# ph2simon(0.05, 0.15, 0.05, 0.2)
# ph2simon(input$p0, input$p1, input$alpha, 1-input$power)
dataset <- datasetInput()
# do.call(what = ph2simon, args = dataset)
dataset
})
# Show the first "n" observations ----
# The use of isolate() is necessary because we don't want the table
# to update whenever input$obs changes (only when the user clicks
# the action button)
# output$view <- renderTable({
# head(datasetInput(), n = isolate(input$alpha))
# })
output$distPlot <- renderPlot({
# x <- faithful$waiting
# bins <- seq(min(x), max(x), length.out = input$bins + 1)
#
# hist(x, breaks = bins, col = "#75AADB", border = "white",
# xlab = "Waiting time to next eruption (in mins)",
# main = "Histogram of waiting times")
# sim_geno(pA = input$bins)
# randomVals()
# sim_geno(pA = randomVals())
dataset <- datasetInput()
ph2out = dataset$out
minimax_idx = which.min(ph2out[,"n"])
optimal_idx = which.min(ph2out[,"EN(p0)"])
minimax = ph2out[minimax_idx,]
optimal = ph2out[optimal_idx,]
plot(x = c(minimax[["n1"]], minimax[["n"]], optimal[["n1"]], optimal[["n"]]), y = c(minimax[["r1"]], minimax[["r"]], optimal[["r1"]], optimal[["r"]]),
col = c("blue", "blue", "red", "red"),
cex = 3, lwd = 3, las = 1,
xlab = "n",
ylab = "r",
xlim = c(0,optimal[["n"]]), ylim = c(0,max(minimax[["r"]], optimal[["r"]])))
})
}
# Create Shiny app ----
shinyApp(ui, server)