Advertisement
Guest User

Minimal shiny app

a guest
Apr 4th, 2022
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. library(shiny)
  2.  
  3. # Define UI for app that draws a histogram ----
  4. ui <- fluidPage(
  5.  
  6. # App title ----
  7. titlePanel("Hello Shiny!"),
  8.  
  9. # Sidebar layout with input and output definitions ----
  10. sidebarLayout(
  11.  
  12. # Sidebar panel for inputs ----
  13. sidebarPanel(
  14.  
  15. # Input: Slider for the number of bins ----
  16. sliderInput(inputId = "bins",
  17. label = "Number of bins:",
  18. min = 1,
  19. max = 50,
  20. value = 30)
  21.  
  22. ),
  23.  
  24. # Main panel for displaying outputs ----
  25. mainPanel(
  26.  
  27. # Output: Histogram ----
  28. plotOutput(outputId = "distPlot")
  29.  
  30. )
  31. )
  32. )
  33.  
  34.  
  35.  
  36. # Define server logic required to draw a histogram ----
  37. server <- function(input, output) {
  38.  
  39. # Histogram of the Old Faithful Geyser Data ----
  40. # with requested number of bins
  41. # This expression that generates a histogram is wrapped in a call
  42. # to renderPlot to indicate that:
  43. #
  44. # 1. It is "reactive" and therefore should be automatically
  45. # re-executed when inputs (input$bins) change
  46. # 2. Its output type is a plot
  47. output$distPlot <- renderPlot({
  48.  
  49. x <- faithful$waiting
  50. bins <- seq(min(x), max(x), length.out = input$bins + 1)
  51.  
  52. hist(x, breaks = bins, col = "#75AADB", border = "white",
  53. xlab = "Waiting time to next eruption (in mins)",
  54. main = "Histogram of waiting times")
  55.  
  56. })
  57.  
  58. }
  59.  
  60.  
  61. shinyApp(ui = ui, server = server)
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement