File: server.R

package info (click to toggle)
r-cran-shiny 1.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,080 kB
  • ctags: 290
  • sloc: makefile: 22; sh: 13
file content (32 lines) | stat: -rw-r--r-- 962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
library(shiny)
library(datasets)

# Define server logic required to summarize and view the
# selected dataset
function(input, output) {

  # Return the requested dataset. Note that we use `eventReactive()`
  # here, which takes a dependency on input$update (the action
  # button), so that the output is only updated when the user
  # clicks the button.
  datasetInput <- eventReactive(input$update, {
    switch(input$dataset,
           "rock" = rock,
           "pressure" = pressure,
           "cars" = cars)
  }, ignoreNULL = FALSE)

  # Generate a summary of the dataset
  output$summary <- renderPrint({
    dataset <- datasetInput()
    summary(dataset)
  })

  # Show the first "n" observations. The use of `isolate()` here
  # is necessary because we don't want the table to update
  # whenever input$obs changes (only when the user clicks the
  # action button).
  output$view <- renderTable({
    head(datasetInput(), n = isolate(input$obs))
  })
}