mirror of
https://github.com/rstudio/shiny.git
synced 2026-02-02 18:55:22 -05:00
let's make the number of bins reactive instead; now it is very clear what the slider really controls a histogram with different number of bins also serves as a good demo of the property of histograms (small bins --> small variance + large bias)
22 lines
643 B
R
22 lines
643 B
R
library(shiny)
|
|
|
|
# Define server logic required to draw a histogram
|
|
shinyServer(function(input, output) {
|
|
|
|
# Expression that generates a histogram. 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({
|
|
x <- faithful[, 2] # Old Faithful Geyser data
|
|
bins <- seq(min(x), max(x), length.out = input$bins + 1)
|
|
|
|
# draw the histogram with the specified number of bins
|
|
hist(x, breaks = bins, col = 'darkgray', border = 'white')
|
|
})
|
|
|
|
})
|