@@ -6,16 +6,11 @@ library(jsonlite)
66library(dplyr )
77library(DT )
88library(plotly )
9- library(mapgl )
10- library(sf )
11-
12- # Set Mapbox token (will use environment variable if available)
13- if (Sys.getenv(" MAPBOX_PUBLIC_TOKEN" ) == " " ) {
14- # Fallback: check for old variable name
15- if (Sys.getenv(" MAPBOX_ACCESS_TOKEN" ) != " " ) {
16- Sys.setenv(MAPBOX_PUBLIC_TOKEN = Sys.getenv(" MAPBOX_ACCESS_TOKEN" ))
17- }
18- }
9+ library(leaflet )
10+ # library(mapgl) # Removed to avoid terra/sf dependency on shinyapps.io
11+ # library(sf) # Removed to avoid terra dependency on shinyapps.io
12+
13+ # Using Leaflet for mapping (no API tokens required)
1914
2015# Load foundation data
2116load_foundation_data <- function () {
@@ -53,7 +48,7 @@ load_metadata <- function() {
5348 return (fromJSON(meta_file ))
5449 } else {
5550 return (list (
56- last_updated = Sys.time( ),
51+ last_updated = format( Sys.Date(), " %B %Y " ),
5752 states_included = c(" CT" , " MA" , " ME" , " NH" , " RI" , " VT" ),
5853 total_foundations = nrow(foundations_data ),
5954 data_source = " ProPublica Nonprofit Explorer API (Sample Data)"
@@ -363,7 +358,7 @@ ui <- fluidPage(
363358
364359 # Map with overlay legend
365360 div(style = " position: relative;" ,
366- mapboxglOutput (" foundation_map" , height = " 700px" ),
361+ leafletOutput (" foundation_map" , height = " 700px" ),
367362
368363 # Compact legend overlay (top-left corner)
369364 div(style = " position: absolute; top: 10px; left: 10px; background: rgba(255, 255, 255, 0.95); border: 2px solid #e0e0e0; padding: 12px 15px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.15); max-width: 280px; font-size: 12px; z-index: 1000;" ,
@@ -807,7 +802,7 @@ server <- function(input, output, session) {
807802 })
808803
809804 # Render map
810- output $ foundation_map <- renderMapboxgl ({
805+ output $ foundation_map <- renderLeaflet ({
811806 data <- filtered_foundations()
812807
813808 # Filter to only rows with valid coordinates
@@ -817,11 +812,9 @@ server <- function(input, output, session) {
817812 if (nrow(map_data ) == 0 ) {
818813 # Return empty map if no geocoded data
819814 return (
820- mapboxgl(
821- style = mapbox_style(" light" ),
822- center = c(- 71.5 , 43.5 ), # Center on New England
823- zoom = 6
824- )
815+ leaflet() %> %
816+ addTiles() %> %
817+ setView(lng = - 71.5 , lat = 43.5 , zoom = 6 ) # Center on New England
825818 )
826819 }
827820
@@ -935,44 +928,25 @@ server <- function(input, output, session) {
935928 return (html )
936929 })
937930
938- # Convert to sf object for mapgl
939- map_sf <- st_as_sf(
940- map_data ,
941- coords = c(" longitude" , " latitude" ),
942- crs = 4326 # WGS84 coordinate system
943- )
944-
945- # Create map
946- mapboxgl(
947- style = mapbox_style(" light" ),
948- center = c(
949- mean(map_data $ longitude , na.rm = TRUE ),
950- mean(map_data $ latitude , na.rm = TRUE )
951- ),
952- zoom = 6 ,
953- pitch = 0 ,
954- bearing = 0
955- ) %> %
956- add_circle_layer(
957- id = " foundations" ,
958- source = map_sf ,
959- circle_color = match_expr(
960- " color" ,
961- values = c(" #27ae60" , " #f1c40f" , " #e74c3c" , " #95a5a6" ),
962- stops = c(" #27ae60" , " #f1c40f" , " #e74c3c" , " #95a5a6" )
963- ),
964- circle_radius = interpolate(
965- column = " circle_size" ,
966- values = c(5 , 20 ),
967- stops = c(5 , 20 )
968- ),
969- circle_opacity = 0.8 ,
970- circle_stroke_color = " #ffffff" ,
971- circle_stroke_width = 2 ,
972- popup = " popup_html" # Changed from tooltip to popup for click interaction
931+ # Create Leaflet map
932+ leaflet(map_data ) %> %
933+ addTiles() %> %
934+ setView(
935+ lng = mean(map_data $ longitude , na.rm = TRUE ),
936+ lat = mean(map_data $ latitude , na.rm = TRUE ),
937+ zoom = 6
973938 ) %> %
974- add_navigation_control(position = " top-right" ) %> %
975- add_fullscreen_control(position = " top-right" )
939+ addCircleMarkers(
940+ lng = ~ longitude ,
941+ lat = ~ latitude ,
942+ radius = ~ circle_size ,
943+ color = " white" ,
944+ weight = 2 ,
945+ opacity = 1 ,
946+ fillColor = ~ color ,
947+ fillOpacity = 0.8 ,
948+ popup = ~ popup_html
949+ )
976950 })
977951}
978952
0 commit comments