Parameterisation can be used to build a website with a page for every region/category/row in your data. This talk at DataHarvest/EIJC 2023 walks through how to do that, with example code and tips.
Beyond PHP - It's not (just) about the codeWim Godden
Most PHP developers focus on writing code. But creating Web applications is about much more than just wrting PHP. Take a step outside the PHP cocoon and into the big PHP ecosphere to find out how small code changes can make a world of difference on servers and network. This talk is an eye-opener for developers who spend over 80% of their time coding, debugging and testing.
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
Today, we almost exclusively think of code in software projects as a collection of text files. The tools that we use (version control systems, IDEs, code analyzers) also use text as the primary storage format for code. In fact, the belief that “code is text” is so deeply ingrained in our heads that we never question its validity or even become aware of the fact that there are other ways to look at code.
In my talk I will explain why treating code as text is a very bad idea which actively holds back our understanding and creates a range of problems in large software projects. I will then show how we can overcome (some of) these problems by treating and storing code as data, and more specifically as a graph. I will show specific examples of how we can use this approach to improve our understanding of large code bases, increase code quality and automate certain aspects of software development.
Finally, I will outline my personal vision of the future of programming, which is a future where we no longer primarily interact with code bases using simple text editors. I will also give some ideas on how we might get to that future.
Love Your Database. An interesting example of how to exploit Postgres' advanced types and of running code in the database. Take a step beyond stored procedures!
This file work is made for the purpose of learning and to get knowledge about programs in big data. Relevant information is taken from various sources. This file was for acadmic purpose and it is shared for learnig purposes
Beyond PHP - It's not (just) about the codeWim Godden
Most PHP developers focus on writing code. But creating Web applications is about much more than just wrting PHP. Take a step outside the PHP cocoon and into the big PHP ecosphere to find out how small code changes can make a world of difference on servers and network. This talk is an eye-opener for developers who spend over 80% of their time coding, debugging and testing.
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
Today, we almost exclusively think of code in software projects as a collection of text files. The tools that we use (version control systems, IDEs, code analyzers) also use text as the primary storage format for code. In fact, the belief that “code is text” is so deeply ingrained in our heads that we never question its validity or even become aware of the fact that there are other ways to look at code.
In my talk I will explain why treating code as text is a very bad idea which actively holds back our understanding and creates a range of problems in large software projects. I will then show how we can overcome (some of) these problems by treating and storing code as data, and more specifically as a graph. I will show specific examples of how we can use this approach to improve our understanding of large code bases, increase code quality and automate certain aspects of software development.
Finally, I will outline my personal vision of the future of programming, which is a future where we no longer primarily interact with code bases using simple text editors. I will also give some ideas on how we might get to that future.
Love Your Database. An interesting example of how to exploit Postgres' advanced types and of running code in the database. Take a step beyond stored procedures!
This file work is made for the purpose of learning and to get knowledge about programs in big data. Relevant information is taken from various sources. This file was for acadmic purpose and it is shared for learnig purposes
This talk will present R as a programming language suited for solving data analysis and modeling problems, MLflow as an open source project to help organizations manage their machine learning lifecycle and the intersection of both by adding support for R in MLflow. It will be highly interactive and touch on some of the technical implementation choices taken while making R available in MLflow. It will also demonstrate using MLflow tracking, projects, and models directly from R as well as reusing R models in MLflow to interoperate with other programming languages and technologies.
Best Data Science Ppt using Python
Data science is an inter-disciplinary field that uses scientific methods, processes, algorithms and systems to extract knowledge and insights from many structural and unstructured data. Data science is related to data mining, machine learning and big data.
Attached here is a presentation that I made covering some bits and pieces of what I got to discover about Data Science and Machine Learning using R Programming Language.
bbyopen/App_Code/.DS_Store
bbyopen/App_Code/VBCode/GoogleMapsAPIHelpers.vb
Imports Microsoft.VisualBasic
Imports System.Xml.Linq
Public Class GoogleMapsAPIHelpers
Public Shared Function GetGeocodingSearchResults(ByVal address As String) As XElement
'Use the Google Geocoding service to get information about the user-entered address
'See http://code.google.com/apis/maps/documentation/geocoding/index.html for more info...
Dim url = String.Format("http://maps.google.com/maps/api/geocode/xml?address={0}&sensor=false", HttpContext.Current.Server.UrlEncode(address))
'Load the XML into an XElement object (whee, LINQ to XML!)
Dim results = XElement.Load(url)
'Check the status
Dim status = results.Element("status").Value
If status <> "OK" AndAlso status <> "ZERO_RESULTS" Then
'Whoops, something else was wrong with the request...
Throw New ApplicationException("There was an error with Google's Geocoding Service: " & status)
End If
Return results
End Function
End Class
bbyopen/App_Data/StoreLocations.mdf
bbyopen/App_Data/StoreLocations_log.LDF
bbyopen/Bin/Microsoft.Web.GeneratedImage.dll
bbyopen/Default.aspx
<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<asp:Content runat="server" ID="myHeadContent" ContentPlaceHolderID="head">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
</script>
<script type="text/javascript">
function init_map(map_canvas_id, lat, lng, zoomLevel) {
var myLatLng = new google.maps.LatLng(lat, lng);
var options = {
zoom: zoomLevel,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map_canvas = document.getElementById(map_canvas_id);
var map = new google.maps.Map(map_canvas, options);
var marker=new google.maps.Marker({
position:myLatLng,
});
marker.setMap(map);
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h2>Welcome!</h2>
<p>
This demo shows how to use the <a href="http://code.google.com/apis/maps/">Google Maps API</a> to build a simple store locator
web application.
</p>
<p>
This demo site is powered by the <code>StoreLocations.mdf</code> database in the <code>App_Data</code> folder, which contains a single
table, <code>Stores</code>. This table has one record for each store, specifying the StoreId, address, city, , zip code, phone, hours,
and latitude and longitude coordinates. From the <a href="FindAStore.aspx">Find a Store ...
Telling factual stories in virtual reality, 360 degree video and augmented re...Paul Bradshaw
Slides from a lecture on the MA in Data Journalism and the MA in Media Production at Birmingham City University, explaining what types of stories and projects suit immersive technologies such as VR and AR, considerations when using them, and techniques employed in the field.
Generative AI tools like ChatGPT and Google Bard are already changing journalism workflows - in this talk for the BBC Local Democracy Reporters conference 2023, Paul Bradshaw walks through a number of ways those tools can help local journalists - and how to avoid the pitfalls and weaknesses of AI including bias and hallucinations.
More Related Content
Similar to How to generate a 100+ page website using parameterisation in R
This talk will present R as a programming language suited for solving data analysis and modeling problems, MLflow as an open source project to help organizations manage their machine learning lifecycle and the intersection of both by adding support for R in MLflow. It will be highly interactive and touch on some of the technical implementation choices taken while making R available in MLflow. It will also demonstrate using MLflow tracking, projects, and models directly from R as well as reusing R models in MLflow to interoperate with other programming languages and technologies.
Best Data Science Ppt using Python
Data science is an inter-disciplinary field that uses scientific methods, processes, algorithms and systems to extract knowledge and insights from many structural and unstructured data. Data science is related to data mining, machine learning and big data.
Attached here is a presentation that I made covering some bits and pieces of what I got to discover about Data Science and Machine Learning using R Programming Language.
bbyopen/App_Code/.DS_Store
bbyopen/App_Code/VBCode/GoogleMapsAPIHelpers.vb
Imports Microsoft.VisualBasic
Imports System.Xml.Linq
Public Class GoogleMapsAPIHelpers
Public Shared Function GetGeocodingSearchResults(ByVal address As String) As XElement
'Use the Google Geocoding service to get information about the user-entered address
'See http://code.google.com/apis/maps/documentation/geocoding/index.html for more info...
Dim url = String.Format("http://maps.google.com/maps/api/geocode/xml?address={0}&sensor=false", HttpContext.Current.Server.UrlEncode(address))
'Load the XML into an XElement object (whee, LINQ to XML!)
Dim results = XElement.Load(url)
'Check the status
Dim status = results.Element("status").Value
If status <> "OK" AndAlso status <> "ZERO_RESULTS" Then
'Whoops, something else was wrong with the request...
Throw New ApplicationException("There was an error with Google's Geocoding Service: " & status)
End If
Return results
End Function
End Class
bbyopen/App_Data/StoreLocations.mdf
bbyopen/App_Data/StoreLocations_log.LDF
bbyopen/Bin/Microsoft.Web.GeneratedImage.dll
bbyopen/Default.aspx
<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<asp:Content runat="server" ID="myHeadContent" ContentPlaceHolderID="head">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
</script>
<script type="text/javascript">
function init_map(map_canvas_id, lat, lng, zoomLevel) {
var myLatLng = new google.maps.LatLng(lat, lng);
var options = {
zoom: zoomLevel,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map_canvas = document.getElementById(map_canvas_id);
var map = new google.maps.Map(map_canvas, options);
var marker=new google.maps.Marker({
position:myLatLng,
});
marker.setMap(map);
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h2>Welcome!</h2>
<p>
This demo shows how to use the <a href="http://code.google.com/apis/maps/">Google Maps API</a> to build a simple store locator
web application.
</p>
<p>
This demo site is powered by the <code>StoreLocations.mdf</code> database in the <code>App_Data</code> folder, which contains a single
table, <code>Stores</code>. This table has one record for each store, specifying the StoreId, address, city, , zip code, phone, hours,
and latitude and longitude coordinates. From the <a href="FindAStore.aspx">Find a Store ...
Telling factual stories in virtual reality, 360 degree video and augmented re...Paul Bradshaw
Slides from a lecture on the MA in Data Journalism and the MA in Media Production at Birmingham City University, explaining what types of stories and projects suit immersive technologies such as VR and AR, considerations when using them, and techniques employed in the field.
Generative AI tools like ChatGPT and Google Bard are already changing journalism workflows - in this talk for the BBC Local Democracy Reporters conference 2023, Paul Bradshaw walks through a number of ways those tools can help local journalists - and how to avoid the pitfalls and weaknesses of AI including bias and hallucinations.
ChatGPT (and generative AI) in journalismPaul Bradshaw
A brief roundup of tips and examples of using ChatGPT and generative AI for journalism (especially data journalism) - presentation from DataHarvest 2023
A brief history of data in journalism, how data journalism differs from forms such as CAR, and what qualities and skills modern data journalism roles involve.
Talk for the Comet Research Centre at Tampere University, Helsinki, Finland, March 2023.
Using narrative structures in shortform and longform journalismPaul Bradshaw
How an understanding of narrative structures can help you write for different platforms and formats, from shortform (Twitter) to news articles and longform features. The second part of a presentation to the Civic Journalism Lab at Newcastle University - you can find the first part at https://www.slideshare.net/onlinejournalist/narrative-and-multiplatform-journalism-part-1
Narrative and multiplatform journalism (part 1)Paul Bradshaw
How an understanding of narrative concepts can help you get to grips with new (and old) platforms and genres. Presentation to the Civic Journalism Lab at Newcastle University - you can find the second part at https://www.slideshare.net/onlinejournalist/using-narrative-structures-in-shortform-and-longform-journalism
Storytelling in the database era: uncertainty and science reportingPaul Bradshaw
Presentation at the Humboldt Foundation's International Journalists' Programmes 2020 about the changes within journalism around using interactivity for telling stories, and communicating uncertainty. The slides also include recommendations around avoiding mistakes.
In September 2019 I spoke at the SciCAR conference in Dortmund, Germany about the experiences of working in a country with well developed open data policies — and the dangers it presents for data journalists.
Normal Labour/ Stages of Labour/ Mechanism of LabourWasim Ak
Normal labor is also termed spontaneous labor, defined as the natural physiological process through which the fetus, placenta, and membranes are expelled from the uterus through the birth canal at term (37 to 42 weeks
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Dr. Vinod Kumar Kanvaria
Exploiting Artificial Intelligence for Empowering Researchers and Faculty,
International FDP on Fundamentals of Research in Social Sciences
at Integral University, Lucknow, 06.06.2024
By Dr. Vinod Kumar Kanvaria
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Safalta Digital marketing institute in Noida, provide complete applications that encompass a huge range of virtual advertising and marketing additives, which includes search engine optimization, virtual communication advertising, pay-per-click on marketing, content material advertising, internet analytics, and greater. These university courses are designed for students who possess a comprehensive understanding of virtual marketing strategies and attributes.Safalta Digital Marketing Institute in Noida is a first choice for young individuals or students who are looking to start their careers in the field of digital advertising. The institute gives specialized courses designed and certification.
for beginners, providing thorough training in areas such as SEO, digital communication marketing, and PPC training in Noida. After finishing the program, students receive the certifications recognised by top different universitie, setting a strong foundation for a successful career in digital marketing.
10. The steps:
● Produce a ‘template’ analysis for a given area
● Produce an index (home) page
● Render multiple .md versions of that analysis -
one for each region
● Render HTML versions
● Publish as a website online (GitHub Pages)
● Debug, clean and tweak the code
11.
12. Go to this URL
github.com/paulbradshaw/
parameterisation
and: https://drive.google.com/drive/folders/17WtozAfB1frGZmLOJbSbJooP1WRDIfY1?usp=sharing
13. The principles:
● Create a parameter — this should be what you
want to generate a different page for (e.g.
region, police force, category, politician)
● Limit code output to what should be in the
HTML file (visible elements)
● Loop through list and call a ‘knitting’ function to
create a file for each
17. Knit - and title it again
Knit the file — you’ll be asked to name it
again
18. Markdown will generate HTML:
● Headings: # or ## or ###
● Italic, bold: * or ** or *** before and after
● Links: [link text](http://url)
● Indented text: >
● Bullet list items: *
● Code blocks: ```{r} above and ``` below
● Inline code: ` before and after
23. ---
title: |
Regional analysis: `r params$reg`
author: "BIGNEWS"
date: "2023-05-25"
output: html_document
params:
reg: "Anyville"
---
What have we added?
Within that list an element called ‘reg’
with a value of ‘Anyville’ is created. We set
it to that value for the purpose of testing.
We define a list variable called ‘params’
The title fetches the ‘params’ list and
then drills down into the ‘reg’ element
within that, and fetches its value
26. ```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Analysing stop and search
Police have been given new powers to stop and
search potential criminals - but are the
existing powers effective - and used fairly?
Find out how the numbers changed in
Add your own Markdown
Level 1
header
(1 hash, then
space)
Code block
with knit
settings (leave
for now)
27. # Analysing stop and search
Police have been given new powers to
stop and search potential criminals -
but are the existing powers effective
- and used fairly? Find out how the
numbers changed in `r params$reg`.
Use the parameter
Inline R code:
‘calls’ the variable
params$reg
28. Code blocks:
```{r}
Code goes here
#add comments to explain
```
● Code blocks and any messages/warnings will
be visible in the HTML version — unless you
specify otherwise in the Knitr settings
29. Code: import packages
```{r import packages}
#import the tidyverse
library(tidyverse)
#The datatables package
library(DT)
```
Another code block -
we’ve named it ‘import
packages’
Code to import
two packages -
with comments
31. Another code
block
```{r import data}
#store the URL
fileloc =
"https://docs.google.com/spreadsheets/d/e/2PACX-
1vR2-w4JWtqaDmOBp7CxZpMaqsa-2Tm4vUVslOf5_NVfiTIa
vYEJWHWOv-4sGJ9VUUlx8eJPnULECeYW/pub?gid=0&singl
e=true&output=csv"
#Tidyverse's read_csv function imports from it
data = read_csv(fileloc)
```
Import the data
Store the
URL of the
CSV
Read the CSV
into a
dataframe
called ‘data’
33. Add two
parameters to
suppress
messages &
warnings
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
warning = F,
message = F)
```
# Analysing stop and search
Police have been given new powers to stop and
search potential criminals - but are the
Change Knitr settings
Change echo=
to FALSE (or F)
to hide code
from output
34. ```{r filter and subset}
#filter to those for this la, and specified cols
subsetdf <- data %>%
dplyr::filter(region == params$reg)
``` Parameter
must match
value in data to
act as filter
Use parameter to filter
35. Extract figures to use
```{r extract figures}
#store the figures for the earliest and latest years
fig21 <- subsetdf$stops_2021
fig22 <- subsetdf$stops_2022
#calculate the change in this region
localchange <- (fig22-fig21)/fig21
#calculate the change across all regions
nationalchange <-
(sum(data$stops_2022)-sum(data$stops_2021))/sum(data$stops_
2021)
```
36. ```{r create custom string}
#set a variable to 'rose' or 'dropped' depending on relation of
earlier figure to newer one
changetype <- ifelse(isTRUE(fig22 > fig21), "rose", "dropped")
#create a custom string with that
customstring1 <- paste0("In **",params$reg,"** the number of stops
",changetype," from **",fig21,"** in 2021 to **",fig22,"** in
2022.")
```
`r customstring1`
Code block: creates a text string, inserting
variables for particular region
Template text + variables
Inline code: ‘calls’ that string variable
37. ```{r create another string}
nationalcomparison <- ifelse(localchange>nationalchange, "higher
than", "below the")
#create a custom string with that
customstring2 <- paste0("The number of people being stopped in 2022
**",changetype," by ",round(localchange*100,1),"%** compared to the
previous year. This is ",nationalcomparison," the national rise of
**",round(nationalchange*100, 1),"%**.")
```
`r customstring2`
Code block: creates a text string, inserting
variables for particular region
Another line…
Inline code: ‘calls’ that string variable
38. That custom string broken down
paste0(
"The number of people being stopped in 2022
**",
changetype,
" by ",
round(localchange*100,1),
"%** compared to the previous year. This is ",
nationalcomparison,
" the national rise of **",
round(nationalchange*100, 1),
"%**.")
39. ## Explore your area
```{r table}
#Create the datatable. Add a caption if you want
DT::datatable(data,
style = 'bootstrap',
caption = 'Numbers of people being stopped and searched',
filter = 'top',
options = list(pageLength = 10, scrollX=TRUE,
autoWidth = TRUE,
order = list(7, 'desc') #order by col 7
), escape = F
)
```
Add an interactive table
Add a heading before the table
Customise these options
40. Tip: clean headings first
Column names often
use underscores or
other characters which
are better replaced
with spaces when used
publicly. Use this code
before the table is
generated.
## Explore your area
```{r clean headings}
#clean column headings
colnames(subsetdf) <-
str_replace(colnames(subsetdf),"_"," ")
```
41. Tip: reduce file size
---
title: |
Regional analysis: `r params$reg`
output:
html_document:
self_contained: false
lib_dir: site/libs
params:
reg: "Anyville"
---
By default each HTML document
contains all the JavaScript it needs - but
this makes it huge. We stop it doing
that.
It now needs to know where to put any
files (JavaScript, CSS) that the HTML
document will need, so we specify a
folder called ‘libs’ inside a ‘site’ folder
44. This is the site’s index.html page
● .Rmd file NEEDS TO BE IN SITE FOLDER
● Use markdown to create the content for your
page — no need for R code blocks
● Headings: # or ## or ###
● Italic, bold: * or ** or *** before and after
● Links: [link text](http://url)
● Indented text, e.g. quotes: >
● Bullet list items: *
46. ---
title: |
Stop and search - get the data
output:
html_document:
df_print: paged
---
The YAML
47. ***This story is available for use by NEWSORG's news partners. Please do not
share outside of the network. It is under strict embargo until November 7 at
0001.***
***Use the dropdown navigation menus across the top of the page to see the
data for a specific local authority***
# What’s the story?
Here's some text for the first part of the page.
## What the experts say
Blah blah.
Example Markdown
49. This will render multiple files
● It will use the template Rmd file as the basis
● It needs a list of regions, and will generate one
for each
50. ```{r import data}
#store the URL
fileloc =
"https://docs.google.com/spreadsheets/d/e/2PACX-1vR2-w4JWtqa
DmOBp7CxZpMaqsa-2Tm4vUVslOf5_NVfiTIavYEJWHWOv-4sGJ9VUUlx8eJP
nULECeYW/pub?gid=0&single=true&output=csv"
data = read_csv(fileloc)
#just get one column - it's now a vector
regions <- data$region
```
Import the data - again
This bit is new. We store a list
of regions to loop through
51. ```{r generate md files}
#store the location of the template
paramsfile <- "01template.Rmd"
#loop through all regions
for (r in regions) {
rmarkdown::render(paramsfile, params = list(reg = r),
output_file =
paste(sep="",'site/',stringr::str_replace_all(r,"
","-"),'.md'),
envir = parent.frame())
}
```
Loop and render
Here is where we set the
params$reg to the region
currently being looped through
52. ```{r generate md files}
#store the location of the template
paramsfile <- "01template.Rmd"
#loop through all regions
for (r in regions) {
rmarkdown::render(paramsfile, params = list(reg = r),
output_file =
paste(sep="",'site/',stringr::str_replace_all(r,"
","-"),'.md'),
envir = parent.frame())
}
```
(Troubleshooting)
This will cause an error if you
haven’t set the YAML to create the
/site folder
55. ```{r get file names}
#get the names of all the html files
filenames <- list.files("site")
```
Make a list of files
The files were all rendered into
a folder called ‘site’ so we are
asking for a list of files in that
folder
56. ```{r generate yaml}
#store the string we want to start out yaml file with
yamlstring <- 'name: "reg"
navbar:
title: "Stop and search"
left:
- text: "Regions"
menu:'
```
Generate the YAML…
This text will be used in the
navigation menu that’s created
The menu part is going to be
filled in next…
57. #create an empty vector to store all the strings we're about to create
strvec <- c()
#loop through the filenames
for (i in filenames){
if(substring(i,nchar(i)-2,nchar(i)) == ".md" ){
#replace spaces with dashes, and replace the file extension with .html
htmlversion <- gsub(" ","-",gsub(".md",".html",i))
#get the name by removing the file extension.
textversion <- gsub(".md","",i)
#create a string for the YAML file by inserting those
fullstring <- paste0('
- text: "',textversion,'"
href: ',htmlversion)
strvec <- c(strvec,fullstring) #add to the collection of strings
}
}
…gather links for it…
58. What’s happening?
● We create an empty list
● Loop through each filename and for each:
● Extract the name to create link text
● Generate a .html version of its filename to
create URL for it
● Add to the empty list
59. #add the initial string
strvec <- c(yamlstring, strvec)
#create a yaml file with that string of text in it
write(strvec, file = "site/_site.yml")
…and write as a .yml file
60. ```{r render site}
#now render the site
rmarkdown::render_site("site")
```
Render the HTML pages
It will look in the /site folder for the
.yml file as the basis for rendering
63. Put website files in a
‘docs’ folder — and
upload to GitHub
● Cannot upload more than 100 files so upload in 3 batches:
● .html files first
● Then the /libs folder (the table uses these files)
● Then the /site_libs folder (navigation uses these)
67. This HTML will need fixing
● <!DOCTYPE html> on page
● Menu doesn’t work on region pages
● Menu might be too long for index page
● (Other things you could do but not worth the time
include: change local CSS/JS links to remote
ones; remove duplicate links; etc)
72. All that in a nutshell
● Parameterisation allows you to generate
multiple files from a single template
● This can be used to build a website with a page
for every region/category/row in your data
● Use GitHub Pages to easily publish that - but
allow time for tweaking and problem-solving
73. More:
● R Markdown: The Definitive Guide has a chapter
on parameterised reports