Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Forked from trestletech/server.R
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcheng5/9492085 to your computer and use it in GitHub Desktop.
Save jcheng5/9492085 to your computer and use it in GitHub Desktop.
Title: Telephones by region
Author: Jeff Allen <jeff@rstudio.com>
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: sidebarlayout helptext selectinput
Type: Shiny
library(shiny)
# Rely on the 'WorldPhones' dataset in the datasets
# package (which generally comes preloaded).
library(datasets)
# Define a server for the Shiny app
shinyServer(function(input, output) {
# Fill in the spot we created for a plot
output$phonePlot <- renderPlot({
# Render a barplot
barplot(WorldPhones[,input$region]*1000,
main=input$region,
ylab="Number of Telephones",
xlab="Year")
})
})
library(shiny)
# Rely on the 'WorldPhones' dataset in the datasets
# package (which generally comes preloaded).
library(datasets)
# Define the overall UI
shinyUI(
# Use a fluid Bootstrap layout
fluidPage(
# Give the page a title
titlePanel("Telephones by region"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
selectInput("region", "Region:",
choices=colnames(WorldPhones)),
hr(),
helpText("Data from AT&T (1961) The World's Telephones.")
),
# Create a spot for the barplot
mainPanel(
plotOutput("phonePlot")
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment