tests/testthat/migrate-apps/01ex/app.R

# Old Faithful
library(shiny)


# Define UI for app that draws a histogram ----
ui <- fluidPage(

  # App title ----
  titlePanel("Hello Shiny!"),

  # Sidebar layout with input and output definitions ----
  sidebarLayout(

    # Sidebar panel for inputs ----
    sidebarPanel(

      # Input: Slider for the number of bins ----
      sliderInput(inputId = "bins",
                  label = "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)

    ),

    # Main panel for displaying outputs ----
    mainPanel(

      # Output: Histogram ----
      plotOutput(outputId = "dist")

    )
  )
)

# Define server logic required to draw a histogram ----
server <- function(input, output, session) {

  x <- faithful$waiting

  bins <- reactive({
    seq(min(x), max(x), length.out = input$bins + 1)
  })

  output$dist <- renderPlot({

    hist(x, breaks = bins(), col = "#75AADB", border = "white",
         xlab = "Waiting time to next eruption (in mins)",
         main = "Histogram of waiting times")

    })

}

# Create Shiny app ----
shinyApp(ui = ui, server = server)
rstudio/shinytest2 documentation built on March 29, 2025, 10:58 p.m.