—
title: “Sta 523 – Midterm 2 – Fall 2018”
output: rmarkdown::html_document
runtime: shiny
—
Due Friday December 7th by 11:59 pm
### Rules
Review all of the rules detailed in `README.md`, if you have any questions please direct them to myself or the TAs.
### Task 1 (20 pts) – Figuring out the NY Times Article Search API
“`
https://developer.nytimes.com/article_search_v2.json?
“`
* `q=` –
* `fq=` –
* `begin_date=` –
* `end_date=` –
* `sort=` –
* `fl=` –
* `hl=` –
* `page=` –
* `facet_field=` –
* `facet_filter=` –
### Task 2 (40 pts) – Getting data from the NY Times Article Search API
“`{r}
get_nyt_articles = function(year, month, day, api_key) {
}
“`
### Task 3 (40 pts) – Shiny Front End
“`{r}
library(shiny)
library(purrr)
shinyApp(
ui = fluidPage(
titlePanel(“NYTimes API”),
sidebarLayout(
sidebarPanel(
sliderInput(“n”,”Number of links”, min = 0, max = 10, value = 5)
),
mainPanel(
uiOutput(“links”)
)
)
),
server = function(input, output, session)
{
state = reactiveValues(
observers = list()
)
observeEvent(input$n, {
# Destroy existing observers
for(i in seq_along(state$observers)) {
state$observers[[i]]$destroy()
}
ui_elems = map(
seq_len(input$n), function(i) fluidRow(actionLink(paste0(“link”,i), paste0(“This is link “,i,”.”)))
)
output$links = renderUI(fluidPage(ui_elems))
# Reset and create new observers for each of our links
state$observers = map(
seq_len(input$n),
function(i) {
label = paste0(“link”,i)
observeEvent(
input[[label]],
{
cat(“You clicked link “, i,”!\n”,sep=””)
},
ignoreInit = TRUE
)
}
)
})
}
)
“`