-
Notifications
You must be signed in to change notification settings - Fork 0
/
02_rmarkdown_interactive.Rmd
63 lines (44 loc) · 1.71 KB
/
02_rmarkdown_interactive.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
title: "HTS Households (interactive)"
author: "Matt Landis"
date: "11/23/2020"
output:
html_document:
code_folding: show
editor_options:
chunk_output_type: console
---
```{r setup}
# Set options
knitr::opts_chunk$set(echo = TRUE, comment = '')
# Load libraries
suppressPackageStartupMessages({
library(data.table)
library(DT)
library(leaflet)
})
# Load data
hh_labeled = readRDS('data/tnc_bayarea_hh_labeled.rds')
hh_map = hh_labeled[
!income_aggregate %in% c('Prefer not to answer', 'Missing: Non-response', 'Missing: Skip logic') & !is.na(income_aggregate)]
hh_table = hh_labeled[, .(hh_id, num_people, income_aggregate, rent_own, res_type)]
```
## Interactive tables with DT
We can make interactive tables of data very simply, using the [DT](https://rstudio.github.io/DT/) package, which is an R interface to the JavaScript library [DataTables](https://datatables.net/).
```{r showdata}
datatable(hh_table)
```
## Interactive maps with leaflet
Making interactive maps is also pretty simple using the [leaflet](https://rstudio.github.io/leaflet/) package, which wraps the JavaScript library [Leaflet](https://leafletjs.com/).
This example has been kept as simple as possible to keep the code readable.
```{r map}
leaflet(hh_map) %>%
addTiles() %>%
addCircleMarkers(
lng=~reported_home_lon,
lat=~reported_home_lat,
radius=3)
```
## About
This is a demonstration project to show how to interact with household travel survey data. The project and all source code is available on [Github](https://github.com/landisrm/rTED_2020).
Note: These data have been fully anonymized by randomizing the ids, locations, and descriptive variables. In addition the actual locations have been jittered.