R/hello.R

Defines functions hello hello.shiny

Documented in hello hello.shiny

#' Hello
#'
#' @export
hello <- function() {
  print("Hello, world!")
}

#' Hello Shiny!
#'
#' @import shiny
#'
#' @export
hello.shiny <- function() {
  ui <- fluidPage(

    # Application title
    titlePanel("Hello Shiny!"),

    # Sidebar with a slider input for number of observations
    sidebarLayout(
      sidebarPanel(
        sliderInput("obs",
                    "Number of observations:",
                    min = 1,
                    max = 1000,
                    value = 500)
      ),

      # Show a plot of the generated distribution
      mainPanel(
        plotOutput("distPlot"),
        div(
          img(src = "img/helloworld.jpg")
        )
      )
    )
  )

  server <- function(input, output) {

    # Expression that generates a plot of the distribution. The expression
    # is wrapped in a call to renderPlot to indicate that:
    #
    #  1) It is "reactive" and therefore should be automatically
    #     re-executed when inputs change
    #  2) Its output type is a plot
    #
    output$distPlot <- renderPlot({

      # generate an rnorm distribution and plot it
      dist <- stats::rnorm(input$obs)
      graphics::hist(dist)
    })

  }

  hello.shiny.app <- shinyApp(ui = ui, server = server)
  runApp(hello.shiny.app, launch.browser = TRUE)
}
mdlama/imageissue documentation built on March 12, 2020, 12:04 a.m.