Last active
June 29, 2018 19:01
-
-
Save trestletech/8522063 to your computer and use it in GitHub Desktop.
An example using a SelectInput element in Shiny to render a plot. Using a sidebar layout and the 'WorldPhones' dataset.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Around the World"), | |
# 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
After running above code I got an error:'height' must be a vector or a matrix.
Would you help me solve this error??