Code Monkey home page Code Monkey logo

Comments (4)

yihui avatar yihui commented on July 28, 2024

How did you build the website? You should not simply run system('hugo') when you have Rmd posts. You have to use blogdown::build_site() instead, or publish the public directory after you call blogdown::serve_site().

from blogdown.

pssguy avatar pssguy commented on July 28, 2024

I run the serve_site() function and this is what I see locally as well. It has now happened with another page which had been working fine i.e. only accessible if full url is put in and does not appear in recent posts. Also the plot expected to appear no longer does

2016-11-24

here is code

---
title: "Hansard"
author: "Andrew Clark"
date: 2016-11-17
categories: ["packages"] 
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE)

UK 2015 Election

I like to check out new and enhanced R packages, particularly those relating to socio-economic issues and sports

A recent new entry is hansard, which pulls data from the UK Parliament API.

Other required packages, which I will make extensive use of in future code extracts, are tidyverse, for data preparation and processing, and
plotly, for a wide set of interactive graphics

The election_results() function retrieves all the results. It takes about 10 seconds to process so I have saved it in a csv file for retrieval in any future manipulation



library(hansard)
library(plotly)
library(tidyverse)

# This function retrieves all the election results and takes a few seconds and has been saved previously

#election_results <- election_results()
#write_csv(election_results,"data/election_results.csv")

#read the saved file
results <- read_csv("../../data/election_results.csv")
# view data.frame
results

Let's say we were interested in how the size of majority is associated with the level of turnout. It might be hypothesised that those constituencies where a tight race was anticipated would have the highest turn-outs - where every vote might count


# filter out unwanted rows and calculate a couple of percentages

df <- results %>%
filter(election.label._value == "2015 General Election") %>% #650
mutate(
to_pc = round(100 * turnout / electorate, 1),
margin_pc = round(100 * majority / turnout, 1)
)

# plot the data, adding a custom info-action
df %>%
plot_ly(
x =  ~ to_pc,
y =  ~ margin_pc,
color = ~ resultOfElection,
hoverinfo = "text",
text = ~ paste0(
constituency.label._value,
"<br>",
resultOfElection,
"<br>Turnout:",
to_pc,
"%<br>Margin:",
margin_pc,
"%"
)
) %>%
layout(
title = "2015 UK General Election Winners Margin and Turnout Percentage",
xaxis = list(title = "% Turnout"),
yaxis = list(title = "% Winner Margin")
) %>%
config(displayModeBar = F, showLink = F)

Well maybe.. but for those of you wanting to model it feel free. What is highlighted is the 'wasted' votes in Labour strongholds.

Hover over any point, if desired after selecting and zooming, for more details


There are plenty more functions within the package and the creator, Evan Odell is actively developing it


I'll recreate the posts under another name to see if that helps

from blogdown.

yihui avatar yihui commented on July 28, 2024

Can I see the source repository of this website? I cannot think of anything only by looking at this single post.

from blogdown.

pssguy avatar pssguy commented on July 28, 2024

I had already deleted the files and recreated under another name and am no longer getting this error. If it reappears, I will reopen with screenshots

from blogdown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.