Slide 12
Slide 12 text
The code
library(shiny)
library(png) ; library(grid) ; library(ggplot2) ; library(DT) ; library(dplyr)
# data loading and raster rendering code removed for brevity
ui <- fluidPage(
fluidRow(column(width = 5, dataTableOutput("brush_info")),
column(width = 7, align = "left",
plotOutput("plot", height = 450, click = "plot_click",
brush = brushOpts(id = "plot_brush", fill = "#ce1256")),
h6("© Transport for London", align = "right", style = "color:blue")))
)
server <- function(input, output) {
output$plot <- renderPlot({
ggplot(stations, aes(long, lat)) +
annotation_custom(bimg, xmin=a, xmax=c, ymin=b, ymax=d) +
geom_point(size = 1, colour = "white", alpha = 0.1) +
ggtitle("Click and drag for station details") +
theme(axis.text.x = element_blank(), axis.text.y = element_blank(),
axis.ticks.length = unit(0.001,"mm"), panel.background = element_blank(),
plot.title = element_text(face = "bold", colour = "red"))})
output$brush_info <- DT::renderDataTable({
brushedPoints(stations, input$plot_brush) %>%
select(Station = station, `Line(s)` = lines, `Entry-Exit` = entry_exit)
}, rownames = FALSE, extensions = 'Scroller',
options = list(deferRender = TRUE, dom = "t", scrollY = 400, scrollCollapse = TRUE))
}
shinyApp(ui = ui, server = server)