I have a simple sample size calculator shiny app im trying to build that I cant seem to figure out.
the inputs consist of 1 numerical input and a series of radio buttons. Im trying to have a different calculation carried dependent on which radiop button is selected
ui <- shinyUI(fluidPage(
titlePanel("alpha"),
sidebarPanel(
numericInput(
"expn",
"Please enter total number of reports received",
1,
min = 0,
max = 1000000
),
radioButtons(
inputId = "'QC_Type'",
label = "QC Type",
choices = c(
"Overall" = "a",
"Solicited" ="b",
"Spontaneous" = "c",
"Clinical Trial"="d",
"Literature"= "e"
)
)
),
mainPanel (
p ("Your required sample size is"),
textOutput("results"))
))
server <- function (input, output) {
A1 <- (1.96*1.96)*(0.3)*(1-0.3)/(0.05*0.05)
B1 <- (1.96*1.96)*(0.32)*(1-0.32)/(0.05*0.05)
C1 <- (1.96*1.96)*(0.35)*(1-0.35)/(0.05*0.05)
D1 <- (1.96*1.96)*(0.26)*(1-0.26)/(0.05*0.05)
E1 <- (1.96*1.96)*(0.36)*(1-0.36)/(0.05*0.05)
options(digits=2)
if (input$QC_Type=="a") {
output$results <- renderText({
as.numeric( (input$expn)*(A1)/(input$expn+(A1)+1))
})
} else if (input$QC_Type=="b") {
output$results <- renderText({
as.numeric( (input$expn)*(B1)/(input$expn+(B1)+1))
})
} else if (input$QC_Type=="c") {
output$results <- renderText({
as.numeric( (input$expn)*(C1)/(input$expn+(C1)+1))
})
} else if (input$QC_Type=="d") {
output$results <- renderText({
as.numeric( (input$expn)*(D1)/(input$expn+(D1)+1))
})
} else if (input$QC_Type=="e") {
output$results <- renderText({
as.numeric( (input$expn)*(E1)/(input$expn+(E1)+1))
})
}
}
shinyApp(ui = ui, server = server)
While the "front end" elements are fine - I cant get the server side to work I get the error message
Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context
Any advice or solutions would be massively appreciated
Cheers
Aucun commentaire:
Enregistrer un commentaire