mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-29 03:00:45 -04:00
add tabsets example
This commit is contained in:
32
inst/examples/tabsets/server.R
Normal file
32
inst/examples/tabsets/server.R
Normal 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())
|
||||
})
|
||||
|
||||
})
|
||||
32
inst/examples/tabsets/ui.R
Normal file
32
inst/examples/tabsets/ui.R
Normal 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"))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user