mirror of
https://github.com/rstudio/shiny.git
synced 2026-01-14 09:28:02 -05:00
45 lines
1.2 KiB
R
45 lines
1.2 KiB
R
library(shiny)
|
|
|
|
# Define server logic for random distribution app ----
|
|
function(input, output, session) {
|
|
|
|
# Reactive expression to generate the requested distribution ----
|
|
# This is called whenever the inputs change. The output functions
|
|
# defined below then use the value computed from this expression
|
|
d <- reactive({
|
|
dist <- switch(input$dist,
|
|
norm = rnorm,
|
|
unif = runif,
|
|
lnorm = rlnorm,
|
|
exp = rexp,
|
|
rnorm)
|
|
|
|
dist(input$n)
|
|
})
|
|
|
|
# Generate a plot of the data ----
|
|
# Also uses the inputs to build the plot label. Note that the
|
|
# dependencies on the inputs and the data reactive expression are
|
|
# both tracked, and all expressions are called in the sequence
|
|
# implied by the dependency graph.
|
|
output$plot <- renderPlot({
|
|
dist <- input$dist
|
|
n <- input$n
|
|
|
|
hist(d(),
|
|
main = paste("r", dist, "(", n, ")", sep = ""),
|
|
col = "#75AADB", border = "white")
|
|
})
|
|
|
|
# Generate a summary of the data ----
|
|
output$summary <- renderPrint({
|
|
summary(d())
|
|
})
|
|
|
|
# Generate an HTML table view of the data ----
|
|
output$table <- renderTable({
|
|
d()
|
|
})
|
|
|
|
}
|