Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo-1/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ shinyServer(function(input, output) {
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})

})
})
2 changes: 1 addition & 1 deletion demo-1/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ shinyUI(fluidPage(
plotOutput("distPlot")
)
)
))
))
6 changes: 4 additions & 2 deletions exercise-1/exercise.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Exercise 1: Loading functions

# Set your directory

setwd('~/OneDrive/Documents/INFO 201/m18-shiny/exercise-1')

# Source your BuildScatter.r script, exposing your BuildScatter function

source('scripts/BuildScatter.R')

# Use your BuildScatter function to draw a well labeled ggplot scatterplot of the iris data
plot <- scatterplot(iris, 'Sepal.Length', 'Petal.Length', 'Species', 'Iris Dataset', 'Sepal Length', 'Petal Length')
plot
8 changes: 8 additions & 0 deletions exercise-1/scripts/BuildScatter.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@
# - Title of the plot (set a default of "Title")
# - Label for the x axis (set a default of "X Title")
# - Label for the y axis (set a default of "Y Title")

scatterplot <- function(df, xaxis, yaxis, color, ptitle = "Title", xlabel = "X Title", ylabel = "Y Title") {
library(ggplot2)
plot <- ggplot(df) +
geom_point(mapping = aes(x = df[, xaxis], y = df[, yaxis], color = df[, color])) +
labs(x = xlabel, y = ylabel, title = ptitle, color = color)
return (plot)
}
6 changes: 4 additions & 2 deletions exercise-3/server.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# server.R
library(dplyr)
library(plotly)
library(shiny)

# Read in data
setwd('~/Documents/info-201/m14-shiny/exercise-3/')
#setwd('~/OneDrive/Documents/info-201/m14-shiny/exercise-3/')
source('./scripts/buildMap.R')
df <- read.csv('./data/electoral_college.csv', stringsAsFactors = FALSE)
state.codes <- read.csv('./data/state_codes.csv', stringsAsFactors = FALSE)
Expand All @@ -18,6 +20,6 @@ shinyServer(function(input, output) {

# Render a plotly object that returns your map
output$map <- renderPlotly({
return(BuildMap(joined.data, 'population'))
return(BuildMap(joined.data, input$var))
})
})
2 changes: 2 additions & 0 deletions exercise-3/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
shinyUI(fluidPage(
mainPanel(
# Add a selectInput (with a proper id) that allows you to select a variable to map
selectInput('var', label = h3('Variable'),
choices = list('Population' = 'population', 'Votes' = 'votes', 'Ratio' = 'ratio')),

# Use plotlyOutput to show your map
plotlyOutput('map')
Expand Down
6 changes: 4 additions & 2 deletions exercise-4/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
library(dplyr)

# Read in data
setwd('~/Documents/info-201/m14-shiny/exercise-4/')
#setwd('~/Documents/info-201/m14-shiny/exercise-4/')
source('./scripts/buildMap.R')
source('./scripts/buildScatter.R')
df <- read.csv('./data/electoral_college.csv', stringsAsFactors = FALSE)
Expand All @@ -23,5 +23,7 @@ shinyServer(function(input, output) {
})

# Create a `scatter` property on your `output` object. That property shoudl be a `renderPlotly` object that returns a scatterplot (`BuildScatter`)

output$scatter <- renderPlotly({
return(BuildScatter(joined.data, input$state))
})
})
19 changes: 12 additions & 7 deletions exercise-4/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@ shinyUI(navbarPage('Electoral College',
plotlyOutput('map')
)
)
)
),

# Create a tabPanel to show your scatter plot

tabPanel('ScatterPlot',
# Add a titlePanel to your tab

titlePanel('State'),

# Create a sidebar layout for this tab (page)

sidebarLayout(

# Create a sidebarPanel for your controls

sidebarPanel(

# Make a textInput widget for searching for a state in your scatter plot

textInput('state', label = 'Select State')
),

# Create a main panel, in which you should display your plotly Scatter plot

mainPanel(
plotlyOutput('scatter')
)
)
)
))