Last active
November 25, 2016 05:39
-
-
Save primaryobjects/6a65dded70f455427f1f to your computer and use it in GitHub Desktop.
Coursera Developing Data Products - Quiz 1
This file contains hidden or 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
# Q1 | |
# Consider the following code for the cars data set | |
# This function plots distance versus speed, each de-meaned and an associated line of slope s. | |
library(manipulate) | |
myPlot <- function(s) { | |
plot(cars$dist - mean(cars$dist), cars$speed - mean(cars$speed)) | |
abline(0, s) | |
} | |
# Which of the following code will make a manipulate plot that creates a slider for the slope? | |
# A | |
manipulate(myPlot(s), s = slider(0, 2, step = 0.1)) | |
# Q2 | |
# Which of the following code uses the rCharts package to create a sortable and searchable data table for the airquality data set? Assume the rCharts package and the airquality data set have already been loaded into R. | |
install.packages("devtools") | |
install.packages("Rcpp") | |
library(devtools) | |
library(Rcpp) | |
install_github('ramnathv/rCharts') | |
library(rCharts) | |
# A | |
dTable(airquality, sPaginationType = "full_numbers") | |
# Q3 | |
# A basic shiny data product requires: | |
# A | |
# A ui.R and server.R file or a A server.R file and a directory called www containing the relevant html files. | |
# Q4 | |
# What is incorrect about the followig syntax in ui.R? | |
library(shiny) | |
shinyUI(pageWithSidebar( | |
headerPanel("Data science FTW!"), | |
sidebarPanel( | |
h2('Big text'), | |
h3('Sidebar') | |
), | |
mainPanel( | |
h3('Main Panel text') | |
) | |
)) | |
# A | |
# Missing a comma in the sidebar panel. | |
# Q5 | |
# Consider the following code in ui.R | |
shinyUI(pageWithSidebar( | |
headerPanel("Example plot"), | |
sidebarPanel( | |
sliderInput('mu', 'Guess at the mu',value = 70, min = 60, max = 80, step = 0.05,) | |
), | |
mainPanel( | |
# HERE: Replace newHist with myHist | |
plotOutput('newHist') | |
) | |
)) | |
library(UsingR) | |
data(galton) | |
shinyServer( | |
function(input, output) { | |
output$myHist <- renderPlot({ | |
hist(galton$child, xlab='child height', col='lightblue',main='Histogram') | |
mu <- input$mu | |
lines(c(mu, mu), c(0, 200),col="red",lwd=5) | |
mse <- mean((galton$child - mu)^2) | |
text(63, 150, paste("mu = ", mu)) | |
text(63, 140, paste("MSE = ", round(mse, 2))) | |
}) } | |
) | |
# Why isn't it doing what we want? | |
# A | |
# The server.R output name isn't the same as the plotOutput command used in ui.R. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment