knitr::opts_chunk$set(echo = TRUE)


## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:


``` r
summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

library(flexdashboard) library(tidyverse) library(plotly) library(shiny)

dat <- read_csv(“path/to/your/csv/cel_volden_wiseman_coursera.csv”)

dat\(Party <- recode(dat\)dem, 1 = “Democrat”, 0 = “Republican”)

#######HINT: for Chart D, you’ll need to set the height of the renderPlot, using the height argument. Try a value of 750. #######Note: You need to replace “path/to/your/csv/cel_volden_wiseman_coursera.csv” with the actual path of your CSV file.

dat %>% drop_na() %>% filter(year > 1979) %>% group_by(year, Party) %>% summarise(passed = sum(all_pass)) %>% ggplot(aes(x = year, y = passed, color = Party)) + geom_line() + labs(title = “Number of Bills Passed by Year and Party”, x = “Year”, y = “Number of Bills Passed”)

dat %>% drop_na() %>% filter(congress == 110) %>% ggplot(aes(x = Party, y = all_pass, fill = Party)) + geom_bar(stat = “identity”) + labs(title = “Bills Passed in the 110th Congress”, x = “Party”, y = “Number of Bills Passed”)

dat %>% drop_na() %>% filter(congress == 110) %>% ggplot(aes(x = dwnom1, y = all_pass, color = Party)) + geom_point() + labs(title = “Bills Passed vs. DW-Nominate Score in the 110th Congress”, x = “DW-Nominate Score”, y = “Number of Bills Passed”)

selectInput(“states”, “Select States:”, choices = unique(dat\(st_name), selected = unique(dat\)st_name), multiple = TRUE)

renderPlot({ filtered_data <- dat %>% filter(st_name %in% input$states, congress == 110) %>% group_by(st_name) %>% summarise(passed = sum(all_pass))

ggplot(filtered_data, aes(x = st_name, y = passed, fill = st_name)) + geom_bar(stat = “identity”) + labs(title = “Bills Passed by State in the 110th Congress”, x = “State”, y = “Number of Bills Passed”) + theme(axis.text.x = element_text(angle = 90, hjust = 1)) }, height = 750)

install.packages(“rsconnect”) rsconnect::setAccountInfo(name=‘[ACCOUNT_NAME]’, token=‘[TOKEN]’, secret=‘[SECRET]’) library(rsconnect) rsconnect::deployApp(‘path/to/your/flexdashboard.Rmd’)