Created
July 27, 2016 10:50
-
-
Save rcatlord/0a50a2e5ca5cab68d83e4223a3192f2e to your computer and use it in GitHub Desktop.
Shiny app integrating timevis and leaflet with a literary theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Bloomsday app ## | |
library(shiny) ; library(leaflet) ; library(timevis) | |
data <- data.frame( | |
id = sample(seq(20, 50, by=1), 18, replace=FALSE), | |
content = c("Telemachus", | |
"Nestor", | |
"Proteus", | |
"Calypso", | |
"Lotus-Eaters", | |
"Hades", | |
"Aeolus", | |
"Lestrygonians", | |
"Scylla & Charybdis", | |
"Wandering Rocks", | |
"Sirens", | |
"Cyclops", | |
"Nausicaa", | |
"Oxen of the Sun", | |
"Circe", | |
"Eumaeus", | |
"Ithaca", | |
"Penelope"), | |
start = c("1904-06-16 08:00:00", | |
"1904-06-16 10:00:00", | |
"1904-06-16 11:00:00", | |
"1904-06-16 08:00:00", | |
"1904-06-16 10:00:00", | |
"1904-06-16 11:00:00", | |
"1904-06-16 12:00:00", | |
"1904-06-16 13:00:00", | |
"1904-06-16 14:00:00", | |
"1904-06-16 15:00:00", | |
"1904-06-16 16:00:00", | |
"1904-06-16 17:00:00", | |
"1904-06-16 20:00:00", | |
"1904-06-16 22:00:00", | |
"1904-06-17 00:00:00", | |
"1904-06-17 01:00:00", | |
"1904-06-17 02:00:00", | |
"1904-06-17 02:00:00"), | |
end = c("1904-06-16 10:00:00", | |
"1904-06-16 11:00:00", | |
"1904-06-16 12:00:00", | |
"1904-06-16 10:00:00", | |
"1904-06-16 11:00:00", | |
"1904-06-16 12:00:00", | |
"1904-06-16 13:00:00", | |
"1904-06-16 14:00:00", | |
"1904-06-16 15:00:00", | |
"1904-06-16 16:00:00", | |
"1904-06-16 17:00:00", | |
"1904-06-16 20:00:00", | |
"1904-06-16 22:00:00", | |
"1904-06-17 00:00:00", | |
"1904-06-17 01:00:00", | |
"1904-06-17 02:00:00", | |
NA, | |
NA), | |
title = c("Martello Tower, Sandycove", | |
"Mr Deasy’s school, Dalkey", | |
"Sandymount Strand", | |
"7 Eccles Street", | |
"Westland Row Post Office, Church, Sweny’s Chemist", | |
"Glasnevin Cemetery", | |
"Offices of the Freeman’s Journal and Evening Telegraph", | |
"Duke Street", | |
"National Library on Kildare Street", | |
"St Mary’s Abbey", | |
"Ormond Hotel bar, Ormond Quay", | |
"Barney Kiernan’s pub, Little Britain Street", | |
"Sandymount Strand", | |
"Holles Street Maternity Hospital", | |
"Bella Cohen’s brothel, Tyrone Street", | |
"Cabman’s shelter, under Loop Line Bridge", | |
"7 Eccles Street", | |
"Blooms’ bedroom at 7 Eccles Street"), | |
type = c(rep("range", 16), "point", "point"), | |
long = c(-6.113661, -6.108661, -6.217688, -6.267056, -6.244118, -6.276854, -6.245630, | |
-6.259024, -6.254471, -6.269370, -6.268832, -6.270982, -6.205113, -6.251141, | |
-6.251197, -6.253692, -6.264922, -6.264922), | |
lat = c(53.288654, 53.276167, 53.336488, 53.358528, 53.344916, 53.369658, 53.340075, | |
53.341949, 53.341175, 53.347736, 53.346247, 53.349324, 53.336011, 53.353596, | |
53.353836, 53.349697, 53.357813, 53.357813) | |
) | |
ui <- fluidPage( | |
fluidRow( | |
column(7, offset = 1, | |
tags$h2("Bloomsday: 16 June 1904"), | |
timevisOutput('timeline'), | |
tags$strong("Data sources:"), | |
tags$a(href="http://jamesjoyce.ie/bloomsday/", "The James Joyce Centre"), | |
" and ", | |
tags$a(href="http://ulysses.bc.edu/#", "Walking Ulysses"), | |
tags$br(), | |
tags$br(), | |
leafletOutput("map"), | |
div(h5(textOutput("caveat"), align = "left"), style = "color:steelblue") | |
) | |
)) | |
server <- function(input, output){ | |
output$timeline <- renderTimevis({ | |
timevis(data, getSelected = TRUE) | |
}) | |
clicked <- eventReactive(input$timeline_selected, { | |
x <- input$timeline_selected | |
return(x) | |
}) | |
output$map <- renderLeaflet({ | |
if (is.null(input$timeline_selected)) {leaflet() %>% | |
addProviderTiles('CartoDB.Positron') %>% | |
setView(-6.258756, 53.342689, 12) | |
} | |
else { | |
popup <- paste0(data$title[data$id == clicked()]) | |
leaflet(data = data[data$id == clicked(), ]) %>% | |
addProviderTiles('CartoDB.Positron') %>% | |
addMarkers(~long, ~lat, popup = popup) | |
} | |
}) | |
output$caveat <- renderText({ | |
req(input$timeline_selected) | |
"NB: the locations are approximate and represent the principal settings of each chapter." | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment