Debian Codegraph @

inst/examples-shiny/08_html/app.R

raw
1 library(shiny)
2
3 # Define server logic for random distribution app ----
4 server <- function(input, output) {
5
6 # Reactive expression to generate the requested distribution ----
7 # This is called whenever the inputs change. The output functions
8 # defined below then use the value computed from this expression
9 d <- reactive({
10 dist <- switch(
11 input$dist,
12 norm = rnorm,
13 unif = runif,
14 lnorm = rlnorm,
15 exp = rexp,
16 rnorm
17 )
18
19 dist(input$n)
20 })
21
22 # Generate a plot of the data ----
23 # Also uses the inputs to build the plot label. Note that the
24 # dependencies on the inputs and the data reactive expression are
25 # both tracked, and all expressions are called in the sequence
26 # implied by the dependency graph.
27 output$plot <- renderPlot({
28 dist <- input$dist
29 n <- input$n
30
31 hist(
32 d(),
33 main = paste("r", dist, "(", n, ")", sep = ""),
34 col = "#75AADB",
35 border = "white"
36 )
37 })
38
39 # Generate a summary of the data ----
40 output$summary <- renderPrint({
41 summary(d())
42 })
43
44 # Generate an HTML table view of the head of the data ----
45 output$table <- renderTable({
46 head(data.frame(x = d()))
47 })
48 }
49
50 # Create Shiny app ----
51 shinyApp(ui = htmlTemplate("www/index.html"), server)