Created
May 21, 2020 10:29
-
-
Save asarolia/769e7719c7f4d7fd6b063f6ee1d25808 to your computer and use it in GitHub Desktop.
app.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
# Define UI ---- | |
ui <- fluidPage( | |
# App title ---- | |
titlePanel("My sample shiny App!"), | |
# 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 = "distPlot") | |
) | |
) | |
) | |
# Define server logic ---- | |
server <- function(input, output) { | |
# Histogram of the Old Faithful Geyser Data ---- | |
# with requested number of bins | |
# This expression that generates a histogram is wrapped in a call | |
# to renderPlot to indicate that: | |
# | |
# 1. It is "reactive" and therefore should be automatically | |
# re-executed when inputs (input$bins) change | |
# 2. Its output type is a plot | |
output$distPlot <- renderPlot({ | |
x <- faithful$waiting | |
bins <- seq(min(x), max(x), length.out = input$bins + 1) | |
hist(x, breaks = bins, col = "#75AADB", border = "white", | |
xlab = "Waiting time to next eruption (in mins)", | |
main = "Histogram of waiting times") | |
}) | |
} | |
#options(shiny.autoreload = TRUE) | |
# options(shiny.host = '127.0.0.1') | |
# options(shiny.port = 3838) | |
# Run the app ---- | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment