- Shiny creates a web application framework for R users
- Shiny allows reactive graphic interface for users to interact with visualizations
- No prior knowledge of HTML, CSS or JavaScript
- Complete online tutorial here
January 17, 2017
leaflet() %>%
addTiles() %>%
addMarkers(lat=40.778883, lng=-77.841371,
popup="University Park, State College")
library(shiny)
shinyApp(
ui <- fluidPage(
leafletOutput("mymap", width = "80%", height = 300),
actionButton("recalc", "New points")),
server <- function(input, output, session) {
points <- eventReactive(input$recalc, {
cbind(rnorm(40) * 2 + 13, rnorm(40) + 48)
}, ignoreNULL = FALSE)
output$mymap <- renderLeaflet({
leaflet() %>% addTiles() %>%
addMarkers(data = points())
})
})
It is important to find a dining place
Input the zip code and miles from zip to find the nearest MacDonald
The distance is calculated using great circle distance measure
Let (lat, lng) to be \((\phi_1, \lambda_1)\) and \((\phi_2, \lambda_2)\)
The central angle \[\Delta\sigma=\text{arccos}(\text{sin}\phi_1\text{sin}\phi_2+\text{cos}\phi_1\text{cos}\phi_2\text{cos}(\Delta\lambda))\]
The arc length (also the great circle distance) \[d=r\Delta\sigma\]
Web application available on ShinyApp.io: https://bolaik.shinyapps.io/MacDonaldMap/
Source code on GitHub: https://github.com/bolaik/ShinyMacDonaldMap
Longitude and Latitude data of zip code: https://gist.github.com/erichurst/7882666
US MacDonald geographic data: https://fusiontables.google.com/DataSource?docid=1HDRk5AjNoPCShwERz_bjyKVGDapFmQil4hl9eMM