mirror of
https://github.com/rstudio/shiny.git
synced 2026-02-07 13:15:00 -05:00
* - Convert all example apps to single file app.R file - Make relevant updates to Readmes to match up with app.R structure - Add color to plots (RStudio blue) - In 04_mpg example: Show outliers by default, as opposed to hide, since this is more routine - In 06_tabsets and 08_html examples: Don't name random data vector "data" - Add extensive comments to app.R files and use consistent formatting of comments across examples - In 09_upload example: Use req() to check for NULL entry * add news entry summarizing changes * use true RStudio blue, #75AADB * Conver shinyApp calls at the end to drop argument name in examples 3-11, except for the custom HTML example. Kept them in for examples 1&2 for completeness in first exporuse to function. * Pull news items that got added before this PR was merged * Update comment for shinyApp function -- it creates an app object, doesn't run the app
60 lines
1.4 KiB
R
60 lines
1.4 KiB
R
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 = "distPlot")
|
|
|
|
)
|
|
)
|
|
)
|
|
|
|
# Define server logic required to draw a histogram ----
|
|
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")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
# Create Shiny app ----
|
|
shinyApp(ui = ui, server = server)
|