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

worked on exercise #4

Open
wants to merge 3 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: 2 additions & 0 deletions exercise-3/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ shinyUI(fluidPage(
mainPanel(
# Add a selectInput (with a proper id) that allows you to select a variable to map

selectInput('mapvar', label = 'Variable to Map', choices = list("Population" = 'population', 'Electoral Votes' = 'votes', 'Votes / Population' = 'ratio')),

# Use plotlyOutput to show your map
plotlyOutput('map')
)
Expand Down
5 changes: 4 additions & 1 deletion 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/m18-shiny/exercise-3')
source('./scripts/buildMap.R')
source('./scripts/buildScatter.R')
df <- read.csv('./data/electoral_college.csv', stringsAsFactors = FALSE)
Expand All @@ -23,5 +23,8 @@ 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$search))
})

})
8 changes: 5 additions & 3 deletions exercise-4/ui.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ui.R
# install.packages("shiny")
library(shiny)
library(plotly)
shinyUI(navbarPage('Electoral College',
Expand All @@ -25,10 +26,10 @@ shinyUI(navbarPage('Electoral College',
# Create a tabPanel to show your scatter plot

# Add a titlePanel to your tab

tabPanel('Scatter',

# Create a sidebar layout for this tab (page)

titlePanel('Population Vs. Vote Power')

# Create a sidebarPanel for your controls

Expand All @@ -37,5 +38,6 @@ shinyUI(navbarPage('Electoral College',


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


)
))
30 changes: 25 additions & 5 deletions exercise-5/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

#Require the following: shiny, HSUAR, dyplr, and ggplot2

library(shiny)
library(HSAUR)
library(dplyr)
library(ggplot2)

#Load the dataset 'womensrole' from the HSUAR package (same way you would load a built in dataset)


data <- womensrole

#Here you will define the data that is shown based on your inputs defined in the UI
#and turn it into an output plot
#Hint: reference the input values using 'input$inputID'
shinyServer(function(input, output) {

#plotNameHere will become what you named your plot in the UI
output$plotNamehere <- renderPlot({
output$plot.of.role <- renderPlot({

#Here use your different input values to define what data is used to render your plot
#The x axis will be the level of education
Expand All @@ -22,17 +26,33 @@ shinyServer(function(input, output) {


#Filter the dataset based on whether the input is Men, Women, or Both


if(input$sex == "Male") {
plot.data <- data %>% filter(sex == "Male")
}
if(input$sex == "Female") {
plot.data <- data %>% filter(sex == "Female")
}
if(input$sex == "Both") {
plot.data <- data
}


#Define a y axis value based on the input Agree or Disagree


if(input$thoughts == "Agree") {
thoughts <- plot.data$agree
}
if(input$thoughts == "Disagree") {
thoughts <- plot.data$disagree
}

#Using the values you just defined, construct a scatterplot using ggplot2
#x will be defined by education, y by agree/disagree
#Bonus: Factor the color field by sex
#(this will allow you to visually see the difference between Men and Women when Both are selected)


ggplot(data = plot.data, aes(x = education, y = thoughts, color = factor(sex))) + geom_point()

})

Expand Down
18 changes: 14 additions & 4 deletions exercise-5/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ library(shiny)
shinyUI(fluidPage(

# Add a descriptive application title
titlePanel("Add Title Here"),
titlePanel("Women's Role in the World Survey"),

# Here you will add the interactivity to your app
# Create a selectInput where the user can select either Men, Women, or Both.
Expand All @@ -19,18 +19,28 @@ shinyUI(fluidPage(
sidebarPanel(
#selectInput for Men, Women, or Both
#inputID = sex

selectInput(
inputId = "sex",
label = "sex:",
choices = c("Male", "Female", "Both"),
selected = "Both"
),

#selectInput for Agree or Disagree
#inputID = thoughts

selectInput(
inputId = "thoughts",
label = "thoughts:",
choices = c("Agree", "Disagree"),
selected = "Agree"
)

),

# Show a plot of the generated distribution
mainPanel(
#give your plot a descriptive name
plotOutput("plotNamehere")
plotOutput("plot.of.role")
)
)
))