Good evening,
I'm trying to create a histogram app and I get the following error message:
Error in rnorm: invalid arguments
Can someone tell me please what I'm doing wrong? I'm stuck on this for hours.
Here is my UI and server codes:
UI
library(shiny)
fluidPage(
pageWithSidebar(
headerPanel("My First Shiny App"),
sidebarPanel(
selectInput(inputId = "Distribution",
label = "Please Select Distribution Type",
choices = c("Normal", "Exponential")),
sliderInput(inputId = "Sample Size",
label = "Please Select Sample Size: ",
min = 100, max = 5000, value = 1000, step = 100),
conditionalPanel(condition = "input.Distribution == 'Normal'",
textInput(inputId = "mean",
label = "Please Select the Mean",
value = 10),
textInput(inputId = "sd",
label = "Please Select Standard Deviation",
value = 3)),
conditionalPanel(condition = "input.Distribution == 'Exponential'",
textInput(inputId = "lambda",
label = "Please Select Exponential Lambda",
value = 1))
),
mainPanel(
plotOutput(outputId = "myPlot")
)
)
)
Server
function(input, output, session) {
output$myPlot <- renderPlot({
distType <- input$Distribution
size <- input$sampleSize
if(distType == "Normal"){
randomVec <- rnorm(
n = size,
mean = as.numeric(input$mean),
sd = as.numeric(input$sd))
}
else {
randomVec <- rexp(
n = size,
rate = 1/as.numeric(input$lambda))
}
hist(x = randomVec, col = "blue")
})
}