Having trouble getting a Shiny program to run

Hello, I am trying to use the shiny app to make a program that predicts what someones run time will be based off an inputted height. This is all based off data that was collected and compiled in an xlxs. file. I cannot get the program to run, my code is attached below.

Server code:
shinyServer(
function(input, output, sessionInfo){

output$myPlot <- renderPlot({
  
  distType <- input$Distribution
  size <- input$sampleSize
  
  if(distType == "Normal"){
    
    randomVec <- rnorm(size, mean = as.numeric(input$))
  }
  else {
    
    randomVec <- rnorm(size, mean = as.numeric(input$mean), sd=as.numeric(input$sd))
  }
  
  hist(randomVec, col="blue")
})

}
)

UI code:
shinyServer(
pageWithSidebar(
headerPanel("My First Shiny App"),

sidebarPanel(
    selectInput("Distribution", "Please Select Distribution Type",
                choices=c("Normal", "Exponential")),
    sliderInput ("sampleSize", "Please Select Sample Size: ",
                 min=100, max=5000, value= 1000, step=100 ),
    conditionalPanel(condition = "input.Distribution == 'Normal'",
                     textInput("mean","Please Select the mean",10),
                     textInput("sd","Please Select Standard Deviation"),3),
    conditionalPanel(condition = "input.Distribution == 'Exponential'",
                     textInput("lambda", "Please Select Exponential Lambda:",
        ),

mainPanel(
  plotOutput("myPlot")
  )

)


)))

This seems to be what you want...note that you don't have to place UI and server code in separate places. Also, shinyServer() should never be used to wrap a user interface.

library(shiny)

ui <- pageWithSidebar(
  headerPanel("My First Shiny App"),
  sidebarPanel(
    selectInput("Distribution", "Please Select Distribution Type",
                choices=c("Normal", "Exponential")),
    sliderInput("sampleSize", "Please Select Sample Size: ",
                min=100, max=5000, value= 1000, step=100 ),
    conditionalPanel(
      condition = "input.Distribution == 'Normal'",
      textInput("mean","Please Select the mean",10),
      textInput("sd","Please Select Standard Deviation", 3)
    ),
    conditionalPanel(
      condition = "input.Distribution == 'Exponential'",
      textInput("lambda", "Please Select Exponential Lambda:",1)
    )
  ),
  mainPanel(plotOutput("myPlot"))
)

server <- function(input, output, sessionInfo) {
  
  output$myPlot <- renderPlot({
    
    distType <- input$Distribution
    size <- input$sampleSize
    
    if(distType == "Normal") {
      randomVec <- rnorm(size, mean = as.numeric(input$mean))
    } else {
      randomVec <- rnorm(size, mean = as.numeric(input$mean), sd=as.numeric(input$sd))
    }
    hist(randomVec, col="blue")
  })
}

shinyApp(ui, server)
1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.