library(shiny)
ui <- fluidPage(
titlePanel("Standard Deviation Estimation Practice"),
# Sidebar with a slider input for sample size
sidebarLayout(
sidebarPanel(
sliderInput("samplesize", h3("Enter a positive whole number as a sample size"), min = 10, max = 500, value = 250),
actionButton(
inputId = "submit_hist",
label = "Press for new Histogram"
),
numericInput("guess", "What is your estimation of the standard deviation of the data in the histogram?", ""),
),
# Show a plot of the generated distribution and pose question
mainPanel(
plotOutput("distPlot"),
textOutput("result")
)
)
)
server <- function(input, output) {
x_val <- eventReactive(input$submit_hist, {
seed1 <- sample.int(1000000, 1)
set.seed(seed1)
sd1 <- sample.int(25, 1)
mean1 <- sample((-300):400, 1)
rnorm(n = req(input$samplesize), mean = mean1, sd = sd1)
})
y_val <- reactive({
sd(req(x_val()))
})
output$distPlot <- renderPlot({
# draw the histogram with the specified number of bins
hist(req(x_val()),
main = "Histogram",
xlab = "Sample Values",
ylab = "Frequency Count",
col = "darkgray",
border = "white"
)
})
output$result <- renderText({
q <- req(input$guess)
if (!isTruthy(q)) {
return(NULL)
}
# print(y_val())
ifelse(q >= (y_val() - 0.5), ifelse(q <= (y_val() + 0.5),
"That is a correct estimation! Good job! Enter a new sample size.",
"That estimate is too big. Try again!"
),
"That estimate is too small. Try again!"
)
})
}
shinyApp(ui = ui, server = server)