app.R 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #
  2. # This is a Shiny web application. You can run the application by clicking
  3. # the 'Run App' button above.
  4. #
  5. # Find out more about building applications with Shiny here:
  6. #
  7. # http://shiny.rstudio.com/
  8. #
  9. library(shiny)
  10. # Define UI for application that draws a histogram
  11. ui <- shinyUI(fluidPage(
  12. # Application title
  13. titlePanel("Old Faithful Geyser Data"),
  14. # Sidebar with a slider input for number of bins
  15. sidebarLayout(
  16. sidebarPanel(
  17. sliderInput("bins",
  18. "Number of bins:",
  19. min = 1,
  20. max = 50,
  21. value = 30)
  22. ),
  23. # Show a plot of the generated distribution
  24. mainPanel(
  25. plotOutput("distPlot")
  26. )
  27. )
  28. ))
  29. # Define server logic required to draw a histogram
  30. server <- shinyServer(function(input, output) {
  31. output$distPlot <- renderPlot({
  32. # generate bins based on input$bins from ui.R
  33. x <- faithful[, 2]
  34. bins <- seq(min(x), max(x), length.out = input$bins + 1)
  35. # draw the histogram with the specified number of bins
  36. hist(x, breaks = bins, col = 'darkgray', border = 'white')
  37. })
  38. })
  39. # Run the application
  40. shinyApp(ui = ui, server = server)