I am pretty new to shiny, and I know y question is fairly simple, but despite doing a lot of research I can not seem to get shiny to render the output of a power of proportions test. I am trying to make a script where a user inputs all the parameters (p1,p2,sig.level,power), and the sample size n is given. I have tried many different methods, but I usually end up at having no output, or the error "exactly one of 'n', 'p1', 'p2', 'power', and 'sig.level' must be NULL". Any help is appreciated, thank you!
my code so far:
ui<-shinyUI(fluidPage(
headerPanel("Power Calculator"),
fluidRow(
column(12,
wellPanel(
helpText("This calculator can help you understand the power of
your experimental design to detect treatment effects. You
can choose
between a standard design in which individuals are randomly
assigned to treatment or control
and a clustered design, in which groups of individuals are assigned to treatment
and control together."),
column(4,
wellPanel(
numericInput('p1a','prop1', value = 0.12, min = 0.01, max = 0.99),
numericInput('p2a', 'prop2', value = 0.14, min = 0.01, max = 0.99),
numericInput('sig.levela','significance level' , value = 0.95, min = 0.9, max = 0.99),
numericInput('powera', 'power level', value = 0.8, min = 0.75, max = 0.99)
),
column(8,
wellPanel(
htmlOutput("nrequired")
)
)
)
)
)
)
)
)
)
server<-shinyServer(
function(input, output) {
sample.size<-reactive({
p1<-input$p1a
p2<-input$p2a
sig.level<-input$sig.level$a
power<-input$power.levela
})
output$nrequired <- renderPrint({
power.prop.test(sample.size)
print(sample.size)
})
}
)
shinyApp(ui=ui,server=server)
The error message comes from power.prop.test
which is caused by passing the reactive expression sample.size
as parameter to it.
Please, try to modify the server function as follows:
server <- shinyServer(function(input, output) {
output$nrequired <- renderPrint({
power.prop.test(p1 = input$p1a, p2 = input$p2a,
sig.level = input$sig.levela, power = input$powera)
})
})
BTW: I was wondering about your choice of the sig.level
parameter of 0.95 while power.prop.test
is using a default value of 0.05.