# # This is a Shiny web application. You can run the application by clicking # the 'Run App' button above. # # Find out more about building applications with Shiny here: # # http://shiny.rstudio.com/ # ## Instructions: ## Add a selection option using radioButtons in the sidebar that let's you choose between a normal and uniform (or other) distributions library(shiny) library(ggplot2) library(gridExtra) # Define UI for application that draws a histogram ui <- fluidPage( # Application title titlePanel("Random distribution generation"), # Sidebar with a slider input for number of bins sidebarLayout( sidebarPanel( radioButtons("distselect","Choose a distribution", c("normal","uniform")), sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30), tags$a("Link to wikipedia",href="http://en.wikipedia.org"), tags$p(), tags$hr(), tags$img(src="https://upload.wikimedia.org/wikipedia/commons/1/14/Michigan_tech_univ_husky_logo.png",width=150) ), # Show a plot of the generated distribution mainPanel( h1("Histogram and normal q-q plot"), plotOutput("distPlot") ) ) ) # Define server logic required to draw a histogram server <- function(input, output) { output$distPlot <- renderPlot({ distchoice <- input$distselect if(distchoice=="normal") { x <- rnorm(1000) } else if(distchoice=="uniform"){ x <- runif(1000) } else{ x <- rnorm(1000) } # draw the histogram with the specified number of bins a <- as.data.frame(x) |> ggplot(aes(x=x)) +geom_histogram(bins=input$bins,fill="orange2",color="black") + theme_bw() b <- as.data.frame(x) |> ggplot(aes(sample=x)) + geom_qq() + theme_bw() grid.arrange(a,b,ncol=2) }) } # Run the application shinyApp(ui = ui, server = server)