add tabsets example

This commit is contained in:
JJ Allaire
2012-07-25 08:51:18 -04:00
parent 649cb69466
commit d0f86078aa
3 changed files with 39 additions and 52 deletions

View File

@@ -0,0 +1,32 @@
library(shiny)
shinyServer(function(input, output) {
data <- reactive(function() {
dist <- switch(input$dist,
norm = rnorm,
unif = runif,
lnorm = rlnorm,
exp = rexp,
rnorm)
dist(as.integer(input$n))
})
output$plot <- reactivePlot(function() {
dist <- input$dist
n <- input$n
hist(data(),
main=paste('r', dist, '(', n, ')', sep=''))
})
output$summary <- reactiveText(function() {
summary(data())
})
output$table <- reactiveTable(function() {
data.frame(x=data())
})
})

View File

@@ -0,0 +1,32 @@
library(shiny)
shinyUI(
pageWithSidebar(
headerPanel(
h1("Tabsets")
),
sidebarPanel(
selectInput("dist", "Distribution type:",
list("Normal" = "norm",
"Uniform" = "unif",
"Log-normal" = "lnorm",
"Exponential" = "exp")),
sliderInput("n",
"Number of observations:",
value = 500,
min = 1,
max = 1000)
),
mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("plot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("table"))
)
)
)
)