diff --git a/.RData b/.RData deleted file mode 100644 index 6c5c510..0000000 Binary files a/.RData and /dev/null differ diff --git a/.Rhistory b/.Rhistory deleted file mode 100644 index 7c033bd..0000000 --- a/.Rhistory +++ /dev/null @@ -1,152 +0,0 @@ -setwd("~/Desktop/IDEA-COVID-StudySafe-SC/studysafe") -shiny::runApp() -shiny::runApp() -runApp('Desktop/IDEA-COVID-StudySafe-SC/studysafe') -library(readr) -bakelite <- read_csv("Desktop/bakelite.csv") -View(bakelite) -plot(bakelite) -bakelite$character <- as.factor(bakelite$character) -plot(bakelite) -p <- ggplot(bakelite) -library(ggplot2) -p <- ggplot(bakelite) -p <- p + geom_histogram(aes(x = character)) -p -ggplot(bakelite) + -geom_histogram(aes(x = character, state="count")) -ggplot(bakelite) + -geom_histogram(aes(x = character, stat="count")) -ggplot(bakelite) + -geom_histogram(aes(x = character), stat="count") -ggplot(bakelite) + -geom_histogram(aes(x = character), stat="count") + -ggtitle("Polyoxybenzylmethylenglycolanhydride (Bakelite)") -library(readr) -transactions <- read_csv("Downloads/transactions.csv") -View(transactions) -saveRDS(transactions, "transactions.Rds") -getwd() -setwd("~/Desktop/COVIDMINDER") -shiny::runApp() -setwd("~/Desktop/CohoesPVApp") -runApp() -runApp() -runApp() -runApp() -runApp() -runApp() -library(rsconnect) -deployApp() -runApp() -runApp() -runApp() -deployApp() -deployApp() -deployApp() -?req -runApp() -runApp() -deployApp() -runApp() -runApp() -deployApp() -runApp() -runApp() -runApp() -deployApp() -deployApp() -deployApp() -runApp() -deployApp() -runApp() -deployApp() -?plotlyOutput -?layout -runApp() -runApp() -runApp() -runApp() -runApp() -deployApp() -shiny::runApp() -runApp() -runApp() -runApp() -runApp() -runApp() -library(rsconnect) -getwd() -deployApp() -runApp() -runApp() -deployApp() -shiny::runApp() -runApp() -runApp() -runApp() -?as.factor -runApp() -runApp() -runApp() -runApp() -runApp() -runApp() -runApp() -?colorFactor -runApp() -runApp() -runApp() -runApp() -library(rsconnect) -deployApp() -shiny::runApp() -library(rsconnect) -deployApp() -runApp() -runApp() -deployApp() -?brewer.pal -shiny::runApp() -runApp() -runApp() -runApp() -runApp() -pal_dam -runApp() -runApp() -names(dam_colors) -dam_colors -runApp() -names(dam_colors) -runApp() -runApp() -runApp() -runApp() -?addLegend -runApp() -runApp() -runApp() -runApp() -runApp() -runApp() -runApp() -runApp() -?brewer.pal -runApp() -?addCircleMarkers -runApp() -runApp() -pal_dam -str(reservoirs_NY$prim_owner) -summary(reservoirs_NY$prim_owner) -summary(as.factor(reservoirs_NY$prim_owner)) -?addLegend -runApp() -runApp() -dam_colors -runApp() -runApp() -runApp() -library(rsconnect) -deployApp() diff --git a/app.R b/app.R index ac416e5..9b2edf3 100644 --- a/app.R +++ b/app.R @@ -2,40 +2,35 @@ library(usmap) # keep library(ggplot2) # keep library(plotly) # keep library(tidyverse) # keep -#library(shinythemes) library(RColorBrewer) # keep library(sf) # keep library(raster) # problems installing `terra` -#library(readr) -#library(maps) -#library(maptools) library(sp) # keep library(leaflet) # keep -#library(tigris) -#library(stringr) +library(maps) -#library(fec16) -# devtools::install_github("baumer-lab/fec12") +# 'devtools::install_github("baumer-lab/fec12")' to install fec12 +# have to install devtools first library(fec12) library(shiny) # keep library(htmltools) # keep -#library(shinybusy) -#library(foreign) # To check what packages we're actually using: #install.packages("NCmisc") # library(NCmisc) # list.functions.in.file("app.R", alphabetic = TRUE) -####### -### Setup for US map -reservoirs <- readRDS("reservoirs.Rds") -reservoirs_trim <- reservoirs %>% - dplyr::select("lat","lon"="long","dam_name","pv_annual_kWh", "prim_owner") -test_data <- data.frame( +# Set up the US map ----- +# Read in the data of all reservoirs in the US and select relevant columns +reservoirs <- readRDS("data/geographical/reservoirs.Rds") +reservoirs_trim <- + reservoirs %>% dplyr::select("lat","lon"="long","dam_name", "pv_annual_kWh", "prim_owner") + +# Convert prim_owner to factor of ownership types +transformed <- data.frame( lon = reservoirs_trim$lon, lat = reservoirs_trim$lat, dam_name = reservoirs_trim$dam_name, @@ -43,332 +38,511 @@ test_data <- data.frame( prim_owner = reservoirs_trim$prim_owner ) -test_data$prim_owner <- factor(test_data$prim_owner, - levels = c("Federal","State","Local Government", "Public Utility","Private")) +transformed$prim_owner <- + factor(transformed$prim_owner, + levels = c("Federal","State","Local Government", "Public Utility","Private")) -test_transformed <- usmap_transform(test_data) +# Line up lon and lat coordinates to those of the regular US map +transformed <- usmap_transform(transformed) -### Setup for NY map -reservoirs_NY <- readRDS("reservoirs_NY.Rds") - -new_york <- readRDS("new_york.Rds") -Tract2District <- readRDS("Tract2District.Rds") +# Set up the NY map ----- +# Read in reservoir and census tract data +ny_reservoirs <- readRDS('data/geographical/ny_reservoirs.Rds') +ny_geodata <- readRDS("data/geographical/new_york_new.Rds") + +# Census tract data for all districts in all states +Tract2District <- readRDS("data/political/Tract2District.Rds") + +# NY districts Tract2District_ny <- Tract2District %>% filter(STATE == "NY") %>% dplyr::select(GEOID, DISTRICT) -new_york <- merge(new_york, Tract2District_ny, by="GEOID") +# Merge NY geodata with districts +ny_geodata <- merge(ny_geodata, Tract2District_ny, by="GEOID") -ny_results <- readRDS("ny_results.Rds") +# NY election results data +ny_elec_results <- readRDS("data/political/ny_results.Rds") -### UI +# UI ----- ui <- fluidPage( - titlePanel("Clean Energy Generation Capacity of Floating Solar on Reservoirs"), - navbarPage(textOutput("input_text"),id = "mainpage", - tabPanel("State Estimated PV Production",value = "homepage", - - sidebarLayout( - sidebarPanel(width = 2, - selectInput(inputId = "state", - label = "Choose a state:", - choices = c("New York"="NY"), - multiple = FALSE), - tags$p(tags$i("More states to be added soon!")), - # TODO: Make district choices dynamic; see: - # https://stackoverflow.com/questions/21465411/r-shiny-passing-reactive-to-selectinput-choices - selectInput("district", "Highlight a district:", - c("1st" = "01", - "2nd" = "02", - "3rd" = "03", - "4th" = "04", - "5th" = "05", - "6th" = "06", - "7th" = "07", - "8th" = "08", - "9th" = "09", - "10th" = "10", - "11th" = "11", - "12th" = "12", - "13th" = "13", - "14th" = "14", - "15th" = "15", - "16th" = "16", - "17th" = "17", - "18th" = "18", - "19th" = "19", - "20th" = "20", - "21st" = "21", - "22nd" = "22", - "23rd" = "23", - "24th" = "24", - "25th" = "25", - "26th" = "26", - "27th" = "27" - ), - selected = "20",width = 150) - ), - mainPanel( - tags$h3("Floating Solar installed on 'suitable' water reservoirs - in the U.S. could generate about 10% of the nation’s - current annual electricity production, according to a 2018 - National Renewable Energy Lab (NREL) study"), - tags$p("This map charts the NREL-identified water reservoirs - potentially 'suitable' for floating solar in this state, - by ownership and potential electricity generation (per MWh)"), - tags$ul( - tags$li(tags$i("Click on a dot to view reservoir name, - estimated PV production and - census tract Low/moderate income percentage.")), - tags$li(tags$i("Select a congressional district (left) to - highlight census tracts in that district.")) - ), - tags$h3(tags$br(),"Potentially Suitable Reservoirs in New York by Census Tract"), - leafletOutput("reservoir_map", height = "750"), - tags$p("Estimated photovoltaic production data provided by National Renewable Energy Laboratory (NREL); see: - Spencer, R. S., Macknick, J., Aznar, A., Warren, A., & Reese, M. O. (2018).", - tags$a("Floating photovoltaic systems: assessing the technical potential of photovoltaic - systems on man-made water bodies in the continental United States.", - href="https://pubs.acs.org/doi/abs/10.1021/acs.est.8b04735"), - "Environmental science & technology, 53(3), 1680-1689.", - "Regarding 'suitability,' the NREL study notes:",tags$i("the high-level data used - and analyzed lacks the resolution for case-by-case - feasibility, and the results should only be considered - as a starting point for national and regional examinations.")), - tags$p("Estimated reservoir area obtained from US Army Corps of Engineers (USACE). - The NREL model and the underlying data are still being validated; - some reservoir location errors might be apparent."), - tags$p("Income data obtained from the US Census.", - tags$i("Low income"),"is defined as up to 50 percent of - the Area Median Income (AMI));",tags$i("moderate income"), - "is defined as greater than 50 percent AMI and up to 80 - percent AMI)."), - tags$p("Developed by the Rensselaer Institute for Data Exploration - and Applications (IDEA) in support of the proposed City of Cohoes, NY - Municipal Floating Solar Demonstration Project."), - tags$p('For more information on the Cohoes, NY Municipal Floating Solar - Demonstration project contact: Theresa Bourgeois, Director of Operations, - City of Cohoes', tags$a('TBourgeois@ci.cohoes.ny.us',href='mailto:TBourgeois@ci.cohoes.ny.us'), 'or 518-903-0142 or Joseph Seman-Graves, City Planner, City of Cohoes', tags$a('JSeman-Graves@ci.cohoes.ny.us',href='mailto:JSeman-Graves@ci.cohoes.ny.us'),'or 518-233-2130'), - - img(src='IDEA_logo_500.png', align = "right", height=75) + # Main website panel + titlePanel("Clean Energy Generation Capacity of Floating Solar on Reservoirs"), + navbarPage( + textOutput("input_text"), + id = "mainpage", + + # State Estimated PV Production tab (homepage) ----- + tabPanel( + "State Estimated PV Production", + value = "homepage", + + # State and district selection + # TODO: Make district choices dynamic + # TODO: Choose districts more elegantly from dataframes + sidebarLayout( + # Side panel + sidebarPanel( + width = 2, + selectInput( + inputId = "state", + label = "Choose a state:", + choices = c("New York"="NY"), multiple = FALSE + ), + tags$p( + tags$i("More states to be added soon!") + ), + selectInput( + "district", + "Highlight a district:", + c("1st" = "01", + "2nd" = "02", + "3rd" = "03", + "4th" = "04", + "5th" = "05", + "6th" = "06", + "7th" = "07", + "8th" = "08", + "9th" = "09", + "10th" = "10", + "11th" = "11", + "12th" = "12", + "13th" = "13", + "14th" = "14", + "15th" = "15", + "16th" = "16", + "17th" = "17", + "18th" = "18", + "19th" = "19", + "20th" = "20", + "21st" = "21", + "22nd" = "22", + "23rd" = "23", + "24th" = "24", + "25th" = "25", + "26th" = "26", + "27th" = "27"), + + # Make default the 20th district (Cohoes) + selected = "20",width = 150 + ) + ), + + # Main panel for map and explanations + mainPanel( + # Explanation above map + tags$h3( + "Floating Solar installed on 'suitable' water reservoirs in the U.S. + could generate about 10% of the nation’s current annual electricity + production, according to a 2018 National Renewable Energy Lab (NREL) + study" + ), + + tags$p( + "This map charts the NREL-identified water reservoirs potentially + 'suitable' for floating solar in this state, by ownership and + potential electricity generation (per MWh)" + ), + + tags$ul( + tags$li( + "Click on a dot to view reservoir name, estimated PV production and + census tract Low/moderate income percentage." + ), + tags$li( + "Select a congressional district (left) to highlight census tracts + in that district." + ), + tags$br() + ), + + # Map + tags$h3("Potentially Suitable Reservoirs in New York by Census Tract"), + leafletOutput("reservoir_map", height = "750"), + + # Explanation below map + tags$p( + tags$br(), + "Estimated photovoltaic production data provided by National + Renewable Energy Laboratory (NREL); see: + Spencer, R. S., Macknick, J., Aznar, A., Warren, A., & Reese, M. O. (2018).", + tags$a( + "Floating photovoltaic systems: assessing the technical potential of + photovoltaic systems on man-made water bodies in the continental United + States.", href="https://pubs.acs.org/doi/abs/10.1021/acs.est.8b04735" + ), + "Environmental science & technology, 53(3), 1680-1689.", + "Regarding 'suitability,' the NREL study notes:", + tags$i( + "the high-level data used and analyzed lacks the resolution for + case-by-case feasibility, and the results should only be considered + as a starting point for national and regional examinations." + ) + ), + + tags$p( + "Estimated reservoir area obtained from US Army Corps of Engineers + (USACE).The NREL model and the underlying data are still being validated; + some reservoir location errors might be apparent." + ), + + tags$p( + "Income data obtained from the US Census.", + tags$i("Low income"), + "is defined as up to 50 percent of the Area Median Income (AMI));", + tags$i("moderate income"), + "is defined as greater than 50 percent AMI and up to 80 percent AMI)." + ), + + tags$p( + "Developed by the Rensselaer Institute for Data Exploration + and Applications (IDEA) in support of the proposed City of Cohoes, NY + Municipal Floating Solar Demonstration Project." + ), + + tags$p( + "For more information on the Cohoes, NY Municipal Floating Solar + Demonstration project contact: Theresa Bourgeois, Director of + Operations, City of Cohoes", + tags$a( + "TBourgeois@ci.cohoes.ny.us", href="mailto:TBourgeois@ci.cohoes.ny.us" + ), + "or 518-903-0142 or Joseph Seman-Graves, City Planner, City of Cohoes", + tags$a( + "JSeman-Graves@ci.cohoes.ny.us", href="mailto:JSeman-Graves@ci.cohoes.ny.us" + ), + "or 518-233-2130" + ), - ) - ) - + img(src='IDEA_logo_500.png', align = "right", height=75) + ) + ) ), - tabPanel("US Estimated PV Production", value ="us_page", - fluidRow(style = "height:100px;", - column(width=12, - tags$h3("Floating Solar installed on 'suitable' water reservoirs - in the U.S. could generate about 10% of the nation’s", - "current annual electricity production, according to a 2018 - National Renewable Energy Lab (NREL) study"), - tags$p("This map charts the 24,419 NREL-identified water reservoirs - potentially 'suitable' for floating solar, by ownership and potential - electricity generation (per MWh)") - ) - ), - fluidRow(style = "height:850px;", - column(width=12, - tags$p(tags$i("Zoom in on a region by clicking, dragging and releasing",tags$br(), - "Reset by selecting 'autoscale' option (hover over upper right of map - to see menu)")), - tags$div(style="float:left;", - plotlyOutput("us_map") - ) - ) - ), - fluidRow(style = "height:200px;", - column(width=12, - tags$p("Estimated photovoltaic production data provided by National Renewable Energy Laboratory (NREL); see: - Spencer, R. S., Macknick, J., Aznar, A., Warren, A., & Reese, M. O. (2018).", - tags$a("Floating photovoltaic systems: assessing the technical potential of photovoltaic - systems on man-made water bodies in the continental United States.", - href="https://pubs.acs.org/doi/abs/10.1021/acs.est.8b04735"), - "Environmental science & technology, 53(3), 1680-1689.", - "Regarding 'suitability,' the NREL study notes:",tags$i("the high-level data used - and analyzed lacks the resolution for case-by-case - feasibility, and the results should only be considered - as a starting point for national and regional examinations.")), - tags$p("Estimated reservoir area obtained from US Army Corps of Engineers (USACE). - The NREL model and the underlying data are still being validated; - some reservoir location errors might be apparent."), - tags$p("Income data obtained from the US Census.", - tags$i("Low income"),"is defined as up to 50 percent of - the Area Median Income (AMI));",tags$i("moderate income"), - "is defined as greater than 50 percent AMI and up to 80 - percent AMI)."), - tags$p("Developed by the Rensselaer Institute for Data Exploration - and Applications (IDEA) in support of the proposed City of Cohoes, NY - Municipal Floating Solar Demonstration Project."), - tags$p('For more information on the Cohoes, NY Municipal Floating Solar - Demonstration project contact: Theresa Bourgeois, Director of Operations, - City of Cohoes', tags$a('TBourgeois@ci.cohoes.ny.us',href='mailto:TBourgeois@ci.cohoes.ny.us'), 'or 518-903-0142 or Joseph Seman-Graves, City Planner, City of Cohoes', tags$a('JSeman-Graves@ci.cohoes.ny.us',href='mailto:JSeman-Graves@ci.cohoes.ny.us'),'or 518-233-2130'), - - img(src='IDEA_logo_500.png', align = "right", height=75) - ) - ), + + + # US Estimated PV Production tab (overview of all reservoirs) ----- + tabPanel( + "US Estimated PV Production", + value ="us_page", + + # Explanation above map + fluidRow( + style = "height:100px;", + column( + width=12, + tags$h3( + "Floating Solar installed on 'suitable' water reservoirs in the U.S. + could generate about 10% of the nation’s current annual electricity + production, according to a 2018 National Renewable Energy Lab (NREL) study" + ), + tags$p( + "This map charts the 24,419 NREL-identified water reservoirs + potentially 'suitable' for floating solar, by ownership and potential + electricity generation (per MWh)" + ) + ) + ), + + # Continue explanation above map and plot the US map + # TODO: Improve the map's interactability + fluidRow( + style = "height:850px;", + column( + width=12, + tags$p( + tags$i( + "Zoom in on a region by clicking, dragging and releasing", + tags$br(), + "Reset by selecting 'autoscale' option + (hover over upper right of map to see menu)" + ) + ), + + tags$div( + style="float:left;", + plotlyOutput("us_map") + ) + ) + ), + + #Explanation below map + fluidRow( + style = "height:200px;", + column( + width=12, + tags$p( + "Estimated photovoltaic production data provided by National + Renewable Energy Laboratory (NREL); see: + Spencer, R. S., Macknick, J., Aznar, A., Warren, A., & Reese, M. O. (2018).", + tags$a( + "Floating photovoltaic systems: assessing the technical potential of + photovoltaic systems on man-made water bodies in the continental + United States.", href="https://pubs.acs.org/doi/abs/10.1021/acs.est.8b04735" + ), + "Environmental science & technology, 53(3), 1680-1689.", + "Regarding 'suitability,' the NREL study notes:", + tags$i( + "the high-level data used and analyzed lacks the resolution for + case-by-case feasibility, and the results should only be considered + as a starting point for national and regional examinations." + ) + ), + + tags$p( + "Estimated reservoir area obtained from US Army Corps of Engineers + (USACE). The NREL model and the underlying data are still being + validated; some reservoir location errors might be apparent." + ), + + tags$p( + "Income data obtained from the US Census.", + tags$i("Low income"), "is defined as up to 50 percent of + the Area Median Income (AMI));", tags$i("moderate income"), "is + defined as greater than 50 percent AMI and up to 80 percent AMI)." + ), + + tags$p( + "Developed by the Rensselaer Institute for Data Exploration + and Applications (IDEA) in support of the proposed City of Cohoes, + NY Municipal Floating Solar Demonstration Project." + ), + + tags$p( + "For more information on the Cohoes, NY Municipal Floating Solar + Demonstration project contact: Theresa Bourgeois, Director of + Operations, City of Cohoes", + tags$a( + "TBourgeois@ci.cohoes.ny.us", href='mailto:TBourgeois@ci.cohoes.ny.us' + ), + 'or 518-903-0142 or Joseph Seman-Graves, City Planner, City of Cohoes', + tags$a( + 'JSeman-Graves@ci.cohoes.ny.us',href='mailto:JSeman-Graves@ci.cohoes.ny.us' + ), + 'or 518-233-2130' + ), + + img(src='IDEA_logo_500.png', align = "right", height=75) + ) + ) ), - tabPanel("About the Floating Solar Explorer",value="about", - tags$h3("About the Floating Solar Explorer"), - - tags$p(img(src='20190731-nrel-fpv-install-53282.jpg', align = "center", height=250)), - tags$p("FPV Installation in Walden, Colorado.", - tags$i("Photo by Dennis Schroeder via", tags$a("NREL",href="https://bit.ly/3cyhq2A"))), - - tags$p("Floating Solar installed on the 24,419 suitable human-made water - reservoirs in the United States could generate about 10% of the nation’s - current annual electricity production, according to a 2018 National - Renewable Energy Lab (NREL) study. The 2018 NREL report indicates - there are 492 reservoirs in New York State alone, encompassing 134,425 - acres of water suitable for Floatovoltaics. This could generate 16.4 TW-hr/yr."), - - tags$p("The City of Cohoes, New York is proposing a",tags$i("municipally - owned and operated"), - "(apparently first of its kind) 3.2 MWdc Floating Solar demonstration project - to be installed on its water reservoir, at a cost of $5.9 million. The Cohoes - clean energy project would demonstrate that leveling the playing field by - providing grants to municipalities — as an alternative option to current - tax credits for private investments — for Floating Solar installations would - incentivize municipalities to invest in their", tags$i("own clean energy - infrastructure"), - "in a sustainable way, while realizing the full economic benefits of - doing so. The Cohoes project may also spark interest in tapping appropriate - water surfaces as a viable platform for solar energy generation, and would - offer K-to-College opportunities for STEM education, workforce development, and research."), - - tags$p('This "Floating Solar Explorer" has been developed by the Rensselaer - Institute for Data Exploration and Applications (IDEA) at Rensselaer - Polytechnic Instuitute in support of the proposed City of Cohoes, NY - Municipal Floating Solar Demonstration Project. This initial collaboration - is designed to visualize the energy-generation opportunities and potential - economic impact of adopting floating solar on human-made water reservoirs. '), - - tags$p("The Floating Solar Explorer’s U.S. map charts the 24,419 NREL-identified - water reservoirs potentially 'suitable' for floating solar, by ownership - and potential electricity generation (per MWh)."), + + + # Background information tab ----- + tabPanel( + "About the Floating Solar Explorer",value="about", + tags$h3("About the Floating Solar Explorer"), + + tags$p( + img(src='20190731-nrel-fpv-install-53282.jpg', align = "center", height=250) + ), + + tags$p( + "FPV Installation in Walden, Colorado.", + tags$i( + "Photo by Dennis Schroeder via", + tags$a("NREL",href="https://bit.ly/3cyhq2A") + ) + ), - tags$p('The New York State map charts the NREL-identified water reservoirs - potentially "suitable" for floating solar in the state, by ownership - and potential electricity generation (per MWh).'), + tags$p( + "Floating Solar installed on the 24,419 suitable human-made water reservoirs + in the United States could generate about 10% of the nation’s current annual + electricity production, according to a 2018 National Renewable Energy Lab + (NREL) study. The 2018 NREL report indicates there are 492 reservoirs in + New York State alone, encompassing 134,425 acres of water suitable for + Floatovoltaics. This could generate 16.4 TW-hr/yr." + ), - tags$p('A municipally owned and operated floating solar installation not only - generates clean energy, it has the capacity to generate economic opportunity for the community as a result of electric bill savings. The City of Cohoes, a Low/Moderate Income (LMI) community with an Environmental Justice (EJ) designation, anticipates saving approximately $500,000 per year in electricity costs; money that can be reinvested back into the working class community.'), + tags$p( + "The City of Cohoes, New York is proposing a", + tags$i("municipally owned and operated"), + "(apparently first of its kind) 3.2 MWdc Floating Solar demonstration project + to be installed on its water reservoir, at a cost of $5.9 million. The Cohoes + clean energy project would demonstrate that leveling the playing field by + providing grants to municipalities — as an alternative option to current + tax credits for private investments — for Floating Solar installations would + incentivize municipalities to invest in their", + tags$i( + "own clean energy infrastructure" + ), + "in a sustainable way, while realizing the full economic benefits of + doing so. The Cohoes project may also spark interest in tapping appropriate + water surfaces as a viable platform for solar energy generation, and would + offer K-to-College opportunities for STEM education, workforce development, + and research." + ), + + tags$p( + 'This "Floating Solar Explorer" has been developed by the Rensselaer + Institute for Data Exploration and Applications (IDEA) at Rensselaer + Polytechnic Instuitute in support of the proposed City of Cohoes, NY + Municipal Floating Solar Demonstration Project. This initial collaboration + is designed to visualize the energy-generation opportunities and potential + economic impact of adopting floating solar on human-made water reservoirs. ' + ), - tags$p('The Floating Solar Explorer incorporates economic data, to better illustrate where the state and national potential is for municipal floating solar installations in LMI communities like Cohoes.'), + tags$p( + "The Floating Solar Explorer’s U.S. map charts the 24,419 NREL-identified + water reservoirs potentially 'suitable' for floating solar, by ownership + and potential electricity generation (per MWh)." + ), - tags$p('Meeting the ambitious and essential clean energy goals that have been set at the Federal, State, and local levels will require all sectors at all levels to do their part. Cities are on the front lines of that effort, and must lead by example to create the necessary changes at the required pace. Municipally owned and operated floating solar installations may offer a new opportunity to generate success.'), + tags$p( + 'The New York State map charts the NREL-identified water reservoirs + potentially "suitable" for floating solar in the state, by ownership + and potential electricity generation (per MWh).' + ), - tags$p('This early-stage Rensselaer IDEA project, developed by students and staff, is an - example of the type of Floating Solar-related undergraduate student engagement - and university-based research projects that can be sparked by and/or help advance - this clean energy technology’s growth in the U.S.'), + tags$p( + 'A municipally owned and operated floating solar installation not only + generates clean energy, it has the capacity to generate economic opportunity + for the community as a result of electric bill savings. The City of Cohoes, + a Low/Moderate Income (LMI) community with an Environmental Justice + (EJ) designation, anticipates saving approximately $500,000 per year + in electricity costs; money that can be reinvested back into the working + class community.' + ), - tags$p(tags$b('Words of support from U.S. Rep. Paul Tonko (D-NY20), Chair of the U.S. - House Energy and Commerce Committee’s Subcommittee on Environment and - Climate Change, in an April 2021 announcement of his request for Federal - funding to implement the Cohoes, NY Municipal Floating Solar Demonstration Project :')), + tags$p( + 'The Floating Solar Explorer incorporates economic data, to better + illustrate where the state and national potential is for municipal + floating solar installations in LMI communities like Cohoes.' + ), - tags$p(tags$blockquote(tags$i('“The Cohoes floating solar initiative offers a groundbreaking opportunity - to localize power generation, increase grid stability and drive down - utility costs for consumers. I applaud this bold collaboration to develop - innovative solutions that will help us realize the full potential of our - energy infrastructure, and I hope this project can serve as a model for - tackling some of America’s thorniest challenges regarding clean energy - generation and preventing the worst outcomes of the climate crisis.” - U.S. Rep Paul Tonko said.'))), + tags$p( + 'Meeting the ambitious and essential clean energy goals that have been + set at the Federal, State, and local levels will require all sectors at + all levels to do their part. Cities are on the front lines of that effort, + and must lead by example to create the necessary changes at the required + pace. Municipally owned and operated floating solar installations may + offer a new opportunity to generate success.' + ), - tags$h3("Background: Data Sources for the Floating Solar Explorer"), + tags$p( + 'This early-stage Rensselaer IDEA project, developed by students and staff, + is an example of the type of Floating Solar-related undergraduate student + engagement and university-based research projects that can be sparked by + and/or help advance this clean energy technology’s growth in the U.S.' + ), - # tags$p("Laura Beshilas (NREL).", tags$a("Floating Solar Photovoltaics Could Make a Big Splash in the USA.",href="https://bit.ly/3cyhq2A"),"(July 29, 2019)"), + tags$p( + tags$b( + 'Words of support from U.S. Rep. Paul Tonko (D-NY20), Chair of the U.S. + House Energy and Commerce Committee’s Subcommittee on Environment and + Climate Change, in an April 2021 announcement of his request for Federal + funding to implement the Cohoes, NY Municipal Floating Solar + Demonstration Project :' + ) + ), - tags$p("Estimated photovoltaic production data provided by National Renewable Energy Laboratory (NREL); see: ", "Spencer, R. S., Macknick, J., Aznar, A., Warren, A., & Reese, M. O. (2018).", tags$a("Floating photovoltaic systems: assessing the technical potential of photovoltaic systems on man-made water bodies in the continental United States.", href="https://pubs.acs.org/doi/abs/10.1021/acs.est.8b04735"), "Environmental science & technology, 53(3), 1680-1689."), + tags$p( + tags$blockquote( + tags$i( + '“The Cohoes floating solar initiative offers a groundbreaking opportunity + to localize power generation, increase grid stability and drive down + utility costs for consumers. I applaud this bold collaboration to develop + innovative solutions that will help us realize the full potential of our + energy infrastructure, and I hope this project can serve as a model for + tackling some of America’s thorniest challenges regarding clean energy + generation and preventing the worst outcomes of the climate crisis.” + U.S. Rep Paul Tonko said.' + ) + ) + ), - # tags$p("World Bank Group.", tags$a("Where Sun Meets Water: Floating Solar Market Report - Executive Summary.", href="http://documents.worldbank.org/curated/en/579941540407455831/Floating-Solar-Market-Report-Executive-Summary"), "Washington, D.C. (October 1, 2018)") + tags$h3("Background: Data Sources for the Floating Solar Explorer"), - tags$p("Estimated reservoir area obtained from US Army Corps of Engineers (USACE)"), + tags$p( + "Estimated photovoltaic production data provided by National Renewable + Energy Laboratory (NREL); see: Spencer, R. S., Macknick, J., Aznar, A., + Warren, A., & Reese, M. O. (2018).", + tags$a( + "Floating photovoltaic systems: assessing the technical potential of + photovoltaic systems on man-made water bodies in the continental United + States.", href="https://pubs.acs.org/doi/abs/10.1021/acs.est.8b04735" + ), + "Environmental science & technology, 53(3), 1680-1689." + ), - tags$p("Income data obtained from US Census"), + tags$p("Estimated reservoir area obtained from US Army Corps of Engineers (USACE)"), - tags$p(" Developed by the Rensselaer Institute for Data Exploration and Applications - (IDEA) in support of the proposed City of Cohoes, NY Municipal Floating Solar - Demonstration Project"), + tags$p("Income data obtained from US Census"), - tags$h3('Other Info:'), + tags$p( + "Developed by the Rensselaer Institute for Data Exploration and + Applications (IDEA) in support of the proposed City of Cohoes, NY + Municipal Floating Solar Demonstration Project" + ), - tags$p('NREL:', tags$a('NREL Details Great Potential for Floating PV Systems; Technology Already in Widespread Use Overseas, Especially in Japan.', - href='https://www.nrel.gov/news/press/2018/nrel-details-great-potential-for-floating-pv-systems.html'), 'News release (Dec. 27, 2018)'), + tags$h3('Other Info:'), - tags$p('About The Rensselaer IDEA:', tags$a('https://idea.rpi.edu/', href='https://idea.rpi.edu/')), + tags$p( + 'NREL:', + tags$a( + 'NREL Details Great Potential for Floating PV Systems; Technology + Already in Widespread Use Overseas, Especially in Japan.', + href='https://www.nrel.gov/news/press/2018/nrel-details-great-potential-for-floating-pv-systems.html' + ), + 'News release (Dec. 27, 2018)' + ), - tags$p('Building Floating Solar in Cohoes:', tags$a('https://www.ci.cohoes.ny.us/523/Building-Floating-Solar-in-Cohoes',href='https://www.ci.cohoes.ny.us/523/Building-Floating-Solar-in-Cohoes')), + tags$p( + 'About The Rensselaer IDEA:', + tags$a( + 'https://idea.rpi.edu/', href='https://idea.rpi.edu/' + ) + ), - tags$p('For more information on the Cohoes, NY Municipal Floating Solar - Demonstration project contact: Theresa Bourgeois, Director of Operations, - City of Cohoes', tags$a('TBourgeois@ci.cohoes.ny.us',href='mailto:TBourgeois@ci.cohoes.ny.us'), 'or 518-903-0142 or Joseph Seman-Graves, City Planner, City of Cohoes', tags$a('JSeman-Graves@ci.cohoes.ny.us',href='mailto:JSeman-Graves@ci.cohoes.ny.us'),'or 518-233-2130'), + tags$p( + 'Building Floating Solar in Cohoes:', + tags$a( + 'https://www.ci.cohoes.ny.us/523/Building-Floating-Solar-in-Cohoes', + href='https://www.ci.cohoes.ny.us/523/Building-Floating-Solar-in-Cohoes' + ) + ), - img(src='IDEA_logo_500.png', align = "right", height=75) + tags$p( + 'For more information on the Cohoes, NY Municipal Floating Solar + Demonstration project contact: Theresa Bourgeois, Director of Operations, + City of Cohoes', + tags$a( + 'TBourgeois@ci.cohoes.ny.us',href='mailto:TBourgeois@ci.cohoes.ny.us' + ), + 'or 518-903-0142 or Joseph Seman-Graves, City Planner, City of Cohoes', + tags$a( + 'JSeman-Graves@ci.cohoes.ny.us', href='mailto:JSeman-Graves@ci.cohoes.ny.us' + ), + 'or 518-233-2130' + ), + img(src='IDEA_logo_500.png', align = "right", height=75) ) ) ) -#### -server <- function(input, output, session){ - output$input_text <- renderText(paste0("Selected state: ",input$state)) +# Server ----- +server <- function(input, output, session) { + # Show currently selected state on the top left corner + output$input_text <- renderText(paste0("Selected State: ",input$state)) + # Read in merged datasets + ny_merged <- readRDS('data/political/ny_merged.Rds') - ny_shp <- readRDS("ny_shp.Rds") + # Plot the NY map (first tab) ----- + # Shading scale for census tracts + bins <- c(0, 20, 40, 60, 80, 100) + ny_pal <- colorBin(palette = "Greys", domain = ny_geodata$Lowmod_pct, bins = bins) - ny_merged <- ny_shp %>% - st_transform(4326) %>% - inner_join(ny_results, by = c("DISTRICT" = "district")) + dam_colors <- brewer.pal(n = 5, name="Accent") - output$us_map <- renderPlotly({ - - p1 <- plot_usmap() + - geom_point(data = test_transformed, - aes(x = lon.1, y = lat.1, - size=pv_annual_kWh, - text = dam_name, - color = prim_owner)) + - labs(title = "Estimated Photovoltaic Production of US Reservoirs", - subtitle = "Source: NREL") + - theme(legend.position = "right") + - scale_colour_manual(name = "Owner Type", values = dam_colors) - - p2 <- ggplotly(p1, tooltip = c("dam_name","prim_owner")) - - m <- list( - l = 50, - r = 50, - b = 100, - t = 100, - pad = 4 - ) - - p2 %>% layout(autosize = F, - width = 1000, height = 900, margin = m, - legend = list( - orientation = "h" - ) - ) - - -}) - - ### For NY Map - pal <- colorNumeric(palette = "Greys", domain = c(0, 1), reverse = FALSE) - - dam_colors <- brewer.pal(n = 5,name="Accent") - dam_labels <- c("Federal", - "State", - "Local Government", - "Public Utility", - "Private") + "State", + "Local Government", + "Public Utility", + "Private") names(dam_colors) <- dam_labels @@ -389,30 +563,28 @@ server <- function(input, output, session){ background: rgba(255,255,255,0.75); font-weight: bold; font-size: 20px; - } -")) + }")) - + # TODO: Select state and district reactively output$reservoir_map <- renderLeaflet({ - - # TODO: Select state and district reactively; update reactively (ie leafletproxy()) - #browser() - - new_york_cd <- new_york %>% filter(DISTRICT == input$district) - - leaflet(new_york_cd) %>% + current_district <- ny_geodata %>% filter(DISTRICT == input$district) + + leaflet(current_district) %>% # Background map addTiles() %>% - # Census tract shapes and shading - addPolygons( - fillColor = new_york_cd$Lowmod_pct, - weight = 1, # 0 seems to speed it up - fillOpacity = 0.2, - color = "black" - ) %>% + # Centering setView(lng = -75.37, lat = 42.98, zoom = 7) %>% - # Reservoir coloring legend + + # Census tract shading within the selected congressional district + addPolygons( + fillColor = ~ny_pal(Lowmod_pct), # color of census tract shading + color = 'black', # color of census tract borders + fillOpacity = 0.75, # opacity of shading + weight = 0.75 # width of census tract border + ) %>% + + # Reservoir coloring legend ('Reservoir Primary Owner Type') addLegend("topleft", #pal = pal_dam, colors = c("#7FC97F","#BEAED4","#FDC086","#FFFF99","#386CB0"), @@ -420,43 +592,80 @@ server <- function(input, output, session){ labels = dam_labels, title = "Reservoir Primary Owner Type", opacity = 1 , - labFormat = function(type, cuts, p) { # Forces correct label order - paste0(dam_labels)} - ) %>% - # Census tract legend + labFormat = function(type, cuts, p){ # Forces correct label order + paste0(dam_labels) + }) %>% + + # Census tract legend ('Percentage Low or Medium Income') addLegend("topleft", - pal = pal, - values = new_york_cd$Lowmod_pct, - title = "Percentage Low or Medium Income", + pal = ny_pal, + values = current_district$Lowmod_pct, + title = "Percentage of Low or Medium Income", opacity = 1) %>% - # Congressional district shapes + + # Congressional district outline + # Placed after census tracts shading code because the outline + # Will be affected by prior opacity settings addPolygons( data = ny_merged, weight = 2, fillOpacity = 0, color = "green" ) %>% - # # Floating map title + + # Floating map title # addControl(title, position = "topleft", className="map-title") %>% # Reservoir markers; must be last! - addCircleMarkers(data=reservoirs_NY, - weight = 2, - opacity = 1, - radius = 5, - fillOpacity = 1, - lng=reservoirs_NY$long, - lat=reservoirs_NY$lat, - color=~pal_dam(as.factor(reservoirs_NY$prim_owner)), - popup = paste0(reservoirs_NY$dam_name,"
", - "Primary Purpose: ", reservoirs_NY$prim_purpose, "
", - "Primary Owner Type: ", reservoirs_NY$prim_owner, "
", - "Low/Mod Income Pct: ",100*reservoirs_NY$Lowmod_pct,"%
", - "Estimated Surface Area (USACE): ",reservoirs_NY$nid_area," acres
", - "Estimated PV Annual Production (NREL): ",reservoirs_NY$pv_annual_kWh/1000," MWh
", - #"GEOID: ",reservoirs_NY$gid, - NULL - )) + addCircleMarkers( + data=ny_reservoirs, + weight = 2, + opacity = 1, + radius = 5, + fillOpacity = 1, + lng=ny_reservoirs$long, + lat=ny_reservoirs$lat, + color=~pal_dam(as.factor(ny_reservoirs$prim_owner)), + popup = paste0( + ny_reservoirs$dam_name,"
", + "Primary Purpose: ", ny_reservoirs$prim_purpose, "
", + "Primary Owner Type: ", ny_reservoirs$prim_owner, "
", + "Low/Mod Income Pct: ", ny_reservoirs$Lowmod_pct,"%
", + "Estimated Surface Area (USACE): ",ny_reservoirs$nid_area," acres
", + "Estimated PV Annual Production (NREL): ",ny_reservoirs$pv_annual_kWh/1000," MWh
", + NULL + ) + ) + }) + + # Plot the US map (second tab) ----- + # TODO: improve interactability + output$us_map <- renderPlotly({ + p1 <- plot_usmap() + + geom_point(data = transformed, + aes(x = lon.1, y = lat.1, + size=pv_annual_kWh, + text = dam_name, + color = prim_owner)) + + labs(title = "Estimated Photovoltaic Production of US Reservoirs", + subtitle = "Source: NREL") + + theme(legend.position = "right") + + scale_colour_manual(name = "Owner Type", values = dam_colors) + + p2 <- ggplotly(p1, tooltip = c("dam_name","prim_owner")) + + m <- list( + l = 50, + r = 50, + b = 100, + t = 100, + pad = 4 + ) + p2 %>% layout(autosize = F, + width = 1000, height = 900, margin = m, + legend = list( + orientation = "h" + )) }) # Content of modal dialog @@ -474,10 +683,7 @@ server <- function(input, output, session){ showModal(query_modal) # Removes modal - observeEvent(input$run, { - removeModal() - }) - + observeEvent(input$run, {removeModal()}) } shinyApp(ui, server) \ No newline at end of file diff --git a/data/geographical/new_hampshire.Rds b/data/geographical/new_hampshire.Rds new file mode 100644 index 0000000..f286e82 Binary files /dev/null and b/data/geographical/new_hampshire.Rds differ diff --git a/new_york.Rds b/data/geographical/new_york.Rds similarity index 100% rename from new_york.Rds rename to data/geographical/new_york.Rds diff --git a/data/geographical/new_york_new.Rds b/data/geographical/new_york_new.Rds new file mode 100644 index 0000000..b118342 Binary files /dev/null and b/data/geographical/new_york_new.Rds differ diff --git a/data/geographical/nh_reservoirs.Rds b/data/geographical/nh_reservoirs.Rds new file mode 100644 index 0000000..4f813ad Binary files /dev/null and b/data/geographical/nh_reservoirs.Rds differ diff --git a/data/geographical/ny_reservoirs.Rds b/data/geographical/ny_reservoirs.Rds new file mode 100644 index 0000000..b5a91b8 Binary files /dev/null and b/data/geographical/ny_reservoirs.Rds differ diff --git a/points_in_ny.Rds b/data/geographical/points_in_ny.Rds similarity index 100% rename from points_in_ny.Rds rename to data/geographical/points_in_ny.Rds diff --git a/reservoirs.Rds b/data/geographical/reservoirs.Rds similarity index 100% rename from reservoirs.Rds rename to data/geographical/reservoirs.Rds diff --git a/reservoirs_NY.Rds b/data/geographical/reservoirs_NY.Rds similarity index 100% rename from reservoirs_NY.Rds rename to data/geographical/reservoirs_NY.Rds diff --git a/Tract2District.Rds b/data/political/Tract2District.Rds similarity index 100% rename from Tract2District.Rds rename to data/political/Tract2District.Rds diff --git a/district_elections.Rds b/data/political/district_elections.Rds similarity index 100% rename from district_elections.Rds rename to data/political/district_elections.Rds diff --git a/districts.Rds b/data/political/districts.Rds similarity index 100% rename from districts.Rds rename to data/political/districts.Rds diff --git a/national_lmi.Rds b/data/political/national_lmi.Rds similarity index 100% rename from national_lmi.Rds rename to data/political/national_lmi.Rds diff --git a/data/political/nh_merged.Rds b/data/political/nh_merged.Rds new file mode 100644 index 0000000..5aa6fab Binary files /dev/null and b/data/political/nh_merged.Rds differ diff --git a/data/political/nh_results.Rds b/data/political/nh_results.Rds new file mode 100644 index 0000000..bf3e438 Binary files /dev/null and b/data/political/nh_results.Rds differ diff --git a/data/political/ny_merged.Rds b/data/political/ny_merged.Rds new file mode 100644 index 0000000..a580c66 Binary files /dev/null and b/data/political/ny_merged.Rds differ diff --git a/data/political/ny_results.Rds b/data/political/ny_results.Rds new file mode 100644 index 0000000..686eab0 Binary files /dev/null and b/data/political/ny_results.Rds differ diff --git a/dataset_generator.R b/dataset_generator.R index 2a14fe9..e19ea8c 100644 --- a/dataset_generator.R +++ b/dataset_generator.R @@ -1,7 +1,7 @@ library(tidyverse) library(RColorBrewer) library(sf) -library(raster) # problems installing `terra` +library(raster) library(readr) library(maps) library(maptools) @@ -12,243 +12,158 @@ library(tigris) library(stringr) # Congressional District stuff - -#library(fec16) library(fec12) library(shiny) library(htmltools) library(shinybusy) library(foreign) -national_dbf <- readRDS("national_lmi.Rds") -options(tigris_class = "sf") +# LMI data ===== +# Obtain national LMI data +national_lmi <- readRDS("data/political/national_lmi.Rds") +options(tigris_class = "sf") # shape file -# Don't break NY!! -# new_york <- tracts(state="NY", cb=F) -# north_carolina <- tracts(state="NC", cb=F) -new_hampshire <- tracts(state="NH", cb=F) -vermont <- tracts(state="VT", cb=F) -alabama <- tracts(state="AL", cb=F) - -# ny_lmi <- national_dbf %>% filter(Stusab=="NY") -# ny_lmi$GEOID <- as.character(ny_lmi$GEOID) -# ny_lmi$GEOID <- str_sub(ny_lmi$GEOID,1,nchar(ny_lmi$GEOID)-1) -# ny_lmi <- ny_lmi %>% -# dplyr::select(GEOID, Lowmod_pct) %>% -# group_by(GEOID) %>% -# mutate(Lowmod_pct = median(Lowmod_pct)) #%>% -# # distinct(GEOID,Lowmod_pct) - - -vt_lmi <- national_dbf %>% filter(Stusab=="VT") -vt_lmi$GEOID <- as.character(vt_lmi$GEOID) -vt_lmi$GEOID <- str_sub(vt_lmi$GEOID,1,nchar(vt_lmi$GEOID)-1) -vt_lmi <- vt_lmi %>% +# Filter state LMI data +ny_lmi <- national_lmi %>% filter(Stusab=="NY") # NY census block groups +ny_lmi$GEOID <- as.character(ny_lmi$GEOID) +ny_lmi$GEOID <- str_sub(ny_lmi$GEOID,1,nchar(ny_lmi$GEOID)-1) # Reduce GEOID to census tract + +# Make the low mod percentage of each census tract the average of all block groups within +# that census tract +ny_lmi_averaged <- ny_lmi %>% dplyr::select(GEOID, Lowmod_pct) %>% group_by(GEOID) %>% - mutate(Lowmod_pct = median(Lowmod_pct)) #%>% -# # distinct(GEOID,Lowmod_pct) + mutate(Lowmod_pct = median(Lowmod_pct)) %>% + dplyr::distinct(GEOID, Lowmod_pct, .keep_all = TRUE) -nh_lmi <- national_dbf %>% filter(Stusab=="NH") +dim(ny_lmi_averaged) # number of census tracts is correct + +nh_lmi <- national_lmi %>% filter(Stusab=="NH") nh_lmi$GEOID <- as.character(nh_lmi$GEOID) nh_lmi$GEOID <- str_sub(nh_lmi$GEOID,1,nchar(nh_lmi$GEOID)-1) -nh_lmi <- nh_lmi %>% +nh_lmi_averaged <- nh_lmi %>% dplyr::select(GEOID, Lowmod_pct) %>% group_by(GEOID) %>% - mutate(Lowmod_pct = median(Lowmod_pct)) #%>% -# # distinct(GEOID,Lowmod_pct) + mutate(Lowmod_pct = median(Lowmod_pct)) %>% + dplyr::distinct(GEOID, Lowmod_pct, .keep_all = TRUE) + -al_lmi <- national_dbf %>% filter(Stusab=="AL") -al_lmi$GEOID <- as.character(al_lmi$GEOID) -al_lmi$GEOID <- str_sub(al_lmi$GEOID,1,nchar(al_lmi$GEOID)-1) -al_lmi <- al_lmi %>% +# Census tract data ===== +# Obtain census tract data from year 2015 to make it coherent with the year of LMI data +ny_tract <- tracts(state = 'NY', year = 2015) +dim(ny_tract) # number of census tracts is correct + +nh_tract <- tracts(state="NH", year = 2015) +# north_carolina <- tracts(state="NC", cb=F) +# vermont <- tracts(state="VT", cb=F) +# alabama <- tracts(state="AL", cb=F) + +## Merge census tract data with LMI data; multiply Lowmod_pct by 100 for visualization purposes +new_york_new <- merge(ny_tract, ny_lmi_averaged, by = 'GEOID') %>% dplyr::select(GEOID, Lowmod_pct) %>% - group_by(GEOID) %>% - mutate(Lowmod_pct = median(Lowmod_pct)) #%>% -# # distinct(GEOID,Lowmod_pct) - -## Now colorize by LMI -new_york <- merge(new_york, ny_lmi) -# north_carolina <- merge(north_carolina, nc_lmi) -new_hampshire <- merge(new_hampshire, nh_lmi) -vermont <- merge(new_hampshire, nh_lmi) -alabama <- merge(new_hampshire, nh_lmi) - -# new_york <- readRDS("new_york.Rds") -# new_hampshire <- readRDS("new_hampshire.Rds") -# north_carolina <- readRDS("north_carolina.Rds") -# vermont <- readRDS("north_carolina.Rds") -# alabama <- readRDS("north_carolina.Rds") - -# results_house is from dec12 package - -# results_house %>% -# group_by(state, district_id) %>% -# summarize(N = n()) %>% -# nrow() -# -# results_house %>% -# left_join(candidates, by = "cand_id") %>% -# dplyr::select(state, district_id, cand_name, party, general_votes) %>% -# arrange(desc(general_votes)) - -# # Focus on a state's results -# # Results by state and district -# district_elections <- results_house %>% -# dplyr::mutate(district = parse_number(district_id)) %>% -# dplyr::group_by(state, district) %>% -# dplyr::summarize( -# N = n(), -# total_votes = sum(general_votes, na.rm = TRUE), -# d_votes = sum(ifelse(party == "D", general_votes, 0), na.rm = TRUE), -# r_votes = sum(ifelse(party == "R", general_votes, 0), na.rm = TRUE) -# ) %>% -# dplyr::mutate( -# other_votes = total_votes - d_votes - r_votes, -# r_prop = r_votes / total_votes, -# winner = ifelse(r_votes > d_votes, "Republican", "Democrat") -# ) - - # ny_results <- district_elections %>% - # dplyr::filter(state == "NY") - - nh_results <- district_elections %>% - dplyr::filter(state == "NH") - - nc_results <- district_elections %>% - dplyr::filter(state == "NC") - - al_results <- district_elections %>% - dplyr::filter(state == "AL") - - vt_results <- district_elections %>% - dplyr::filter(state == "VT") - - # ny_shp <- districts %>% - # dplyr::filter(STATENAME == "New York") - # - nh_shp <- districts %>% - dplyr::filter(STATENAME == "New Hampshire") - - nc_shp <- districts %>% - dplyr::filter(STATENAME == "North Carolina") - - vt_shp <- districts %>% - dplyr::filter(STATENAME == "Vermont") - - al_shp <- districts %>% - dplyr::filter(STATENAME == "Alabama") - - # - # # - # ny_merged <- ny_shp %>% - # st_transform(4326) %>% - # inner_join(ny_results, by = c("DISTRICT" = "district")) - # - nc_merged <- nc_shp %>% - st_transform(4326) %>% - inner_join(nc_results, by = c("DISTRICT" = "district")) - - nh_merged <- nh_shp %>% - st_transform(4326) %>% - inner_join(nh_results, by = c("DISTRICT" = "district")) - - vt_merged <- vt_shp %>% - st_transform(4326) %>% - inner_join(vt_results, by = c("DISTRICT" = "district")) - - al_merged <- al_shp %>% - st_transform(4326) %>% - inner_join(al_results, by = c("DISTRICT" = "district")) - - - # TODO: Reduce "merged" to only what's needed - # ny_merged <- readRDS("ny_merged.Rds") - # nh_merged <- readRDS("nh_merged.Rds") - # nc_merged <- readRDS("nc_merged.Rds") - - ########### - - # Our reservoirs dataset does have state abbreviations! - reservoirs <- readRDS("reservoirs.Rds") - - # TODO: Filter by state choice - # reservoirs_NY <- reservoirs %>% filter(state == "NY") - reservoirs_NC <- reservoirs %>% filter(state == "NC") - reservoirs_NH <- reservoirs %>% filter(state == "NH") - reservoirs_VT <- reservoirs %>% filter(state == "VT") - reservoirs_AL <- reservoirs %>% filter(state == "AL") - - reservoirs_spatial_ny <- reservoirs_NY %>% - st_as_sf(coords=c("long", "lat"), crs = "+proj=longlat") %>% - st_transform(crs=st_crs(new_york)) - - reservoirs_spatial_nh <- reservoirs_NH %>% - st_as_sf(coords=c("long", "lat"), crs = "+proj=longlat") %>% - st_transform(crs=st_crs(new_hampshire)) - - reservoirs_spatial_nc <- reservoirs_NC %>% - st_as_sf(coords=c("long", "lat"), crs = "+proj=longlat") %>% - st_transform(crs=st_crs(north_carolina)) - - reservoirs_spatial_al <- reservoirs_AL %>% - st_as_sf(coords=c("long", "lat"), crs = "+proj=longlat") %>% - st_transform(crs=st_crs(alabama)) - - reservoirs_spatial_vt <- reservoirs_VT %>% - st_as_sf(coords=c("long", "lat"), crs = "+proj=longlat") %>% - st_transform(crs=st_crs(vermont)) - - # points_in_ny <- st_join(new_york, reservoirs_spatial_ny, left=T) - points_in_nc <- st_join(north_carolina, reservoirs_spatial_nc, left=T) - points_in_nh <- st_join(new_hampshire, reservoirs_spatial_nh, left=T) - points_in_al <- st_join(alabama, reservoirs_spatial_al, left=T) - points_in_vt <- st_join(vermont, reservoirs_spatial_vt, left=T) - - # dam_Lowmod_pct_ny <- points_in_ny[,c("dam_name","Lowmod_pct")] - # dam_Lowmod_pct_ny <- dam_Lowmod_pct_ny[,1:2] - - dam_Lowmod_pct_nh <- points_in_nh[,c("dam_name","Lowmod_pct")] - dam_Lowmod_pct_nh <- dam_Lowmod_pct_nh[,1:2] - - dam_Lowmod_pct_nc <- points_in_nc[,c("dam_name","Lowmod_pct")] - dam_Lowmod_pct_nc <- dam_Lowmod_pct_nc[,1:2] - - dam_Lowmod_pct_vt <- points_in_vt[,c("dam_name","Lowmod_pct")] - dam_Lowmod_pct_vt <- dam_Lowmod_pct_vt[,1:2] - - dam_Lowmod_pct_al <- points_in_al[,c("dam_name","Lowmod_pct")] - dam_Lowmod_pct_al <- dam_Lowmod_pct_al[,1:2] - - # saveRDS(dam_Lowmod_pct_ny,"dam_Lowmod_pct_ny.Rds") - saveRDS(dam_Lowmod_pct_nc,"dam_Lowmod_pct_nc.Rds") - saveRDS(dam_Lowmod_pct_nh,"dam_Lowmod_pct_nh.Rds") - saveRDS(dam_Lowmod_pct_vt,"dam_Lowmod_pct_vt.Rds") - saveRDS(dam_Lowmod_pct_al,"dam_Lowmod_pct_al.Rds") - - # dam_Lowmod_pct_ny <- readRDS("dam_Lowmod_pct_ny.Rds") - # dam_Lowmod_pct_nc <- readRDS("dam_Lowmod_pct_nc.Rds") - # dam_Lowmod_pct_nh <- readRDS("dam_Lowmod_pct_nh.Rds") - # dam_Lowmod_pct_vt <- readRDS("dam_Lowmod_pct_vt.Rds") - # dam_Lowmod_pct_al <- readRDS("dam_Lowmod_pct_al.Rds") - - reservoirs_NY <- base::merge(reservoirs_NY,dam_Lowmod_pct_ny,by="dam_name" ) - # reservoirs_NH <- base::merge(reservoirs_NH,dam_Lowmod_pct_nh,by="dam_name" ) - # reservoirs_NC <- base::merge(reservoirs_NC,dam_Lowmod_pct_nc,by="dam_name" ) - # reservoirs_VT <- base::merge(reservoirs_VT,dam_Lowmod_pct_vt,by="dam_name" ) - # reservoirs_AL <- base::merge(reservoirs_AL,dam_Lowmod_pct_al,by="dam_name" ) - - # saveRDS(reservoirs_NC,"reservoirs_NC.Rds") - # saveRDS(reservoirs_NH,"reservoirs_NH.Rds") - # saveRDS(reservoirs_NY,"reservoirs_NY.Rds") - # saveRDS(reservoirs_VT,"reservoirs_VT.Rds") - # saveRDS(reservoirs_AL,"reservoirs_AL.Rds") - - # reservoirs_NC <- readRDS("reservoirs_NC.Rds") - # reservoirs_NH <- readRDS("reservoirs_NH.Rds") - # reservoirs_NY <- readRDS("reservoirs_NY.Rds") - # reservoirs_VT <- readRDS("reservoirs_VT.Rds") - # reservoirs_AL <- readRDS("reservoirs_AL.Rds") - + mutate(Lowmod_pct = Lowmod_pct * 100) +# %>% dplyr::select(GEOID, Lowmod_pct) + +new_hampshire <- merge(nh_tract, nh_lmi_averaged, by = 'GEOID') %>% + dplyr::select(GEOID, Lowmod_pct) %>% + mutate(Lowmod_pct = Lowmod_pct * 100) + +saveRDS(new_york_new, 'data/geographical/new_york_new.Rds') +saveRDS(new_hampshire, 'data/geographical/new_hampshire.Rds') + + +# Federal election results ===== +# results_house is from fec12 +results_house %>% + group_by(state, district_id) %>% + summarize(N = n()) %>% + nrow() + +results_house %>% + left_join(candidates, by = "cand_id") %>% + dplyr::select(state, district_id, cand_name, party, general_votes) %>% + arrange(desc(general_votes)) + +# District elections data ===== +district_elections <- results_house %>% + dplyr::mutate(district = parse_number(district_id)) %>% + dplyr::group_by(state, district) %>% + dplyr::summarize( + N = n(), + total_votes = sum(general_votes, na.rm = TRUE), + d_votes = sum(ifelse(party == "D", general_votes, 0), na.rm = TRUE), + r_votes = sum(ifelse(party == "R", general_votes, 0), na.rm = TRUE) + ) %>% + dplyr::mutate( + other_votes = total_votes - d_votes - r_votes, + r_prop = r_votes / total_votes, + winner = ifelse(r_votes > d_votes, "Republican", "Democrat") + ) + +# Results of individual states +ny_results <- district_elections %>% + dplyr::filter(state == "NY") + +nh_results <- district_elections %>% + dplyr::filter(state == "NH") + +saveRDS(ny_results, 'data/political/ny_results.Rds') +saveRDS(nh_results, 'data/political/nh_results.Rds') + + +# Congressional districts data ===== +districts <- readRDS('data/political/districts.Rds') + +# Filter to individual states and get rid of unused columns +ny_shp <- districts %>% + dplyr::filter(STATENAME == "New York") %>% + dplyr::select(STATENAME, ID, DISTRICT) + +nh_shp <- districts %>% + dplyr::filter(STATENAME == "New Hampshire") %>% + dplyr::select(STATENAME, ID, DISTRICT) + +# Merge with election result data +ny_merged <- ny_shp %>% + st_transform(4326) %>% + inner_join(ny_results, by = c("DISTRICT" = "district")) + +nh_merged <- nh_shp %>% + st_transform(4326) %>% + inner_join(nh_results, by = c("DISTRICT" = "district")) + +saveRDS(ny_merged, 'data/political/ny_merged.Rds') +saveRDS(nh_merged, 'data/political/nh_merged.Rds') + + +# Geographical data ===== +# Read in reservoirs data +reservoirs <- readRDS("data/geographical/reservoirs.Rds") + +# Filter to individual states +ny_reservoirs <- reservoirs %>% filter(state == "NY") +nh_reservoirs <- reservoirs %>% filter(state == "NH") + +# Convert to coordinates +ny_reservoirs_spatial <- ny_reservoirs %>% + st_as_sf(coords=c("long", "lat"), crs = "+proj=longlat") %>% + st_transform(crs=st_crs(new_york_new)) + +nh_reservoirs_spatial <- nh_reservoirs %>% + st_as_sf(coords=c("long", "lat"), crs = "+proj=longlat") %>% + st_transform(crs=st_crs(new_hampshire)) + +# Merge with state geographic data +points_in_ny <- st_join(ny_reservoirs_spatial, new_york_new, left=T) +points_in_nh <- st_join(new_hampshire, nh_reservoirs_spatial, left=T) + +points_in_ny <- points_in_ny[,c("dam_name","Lowmod_pct")] +points_in_nh <- points_in_nh[,c("dam_name","Lowmod_pct")] + +ny_reservoirs_merged <- base::merge(ny_reservoirs, points_in_ny, by="dam_name") +nh_reservoirs_merged <- base::merge(nh_reservoirs, points_in_nh, by="dam_name") + +saveRDS(ny_reservoirs_merged,"data/geographical/ny_reservoirs.Rds") +saveRDS(nh_reservoirs_merged,"data/geographical/nh_reservoirs.Rds") \ No newline at end of file diff --git a/www/20190731-nrel-fpv-install-53282.jpg b/images/20190731-nrel-fpv-install-53282.jpg similarity index 100% rename from www/20190731-nrel-fpv-install-53282.jpg rename to images/20190731-nrel-fpv-install-53282.jpg diff --git a/www/IDEA_logo_500.png b/images/IDEA_logo_500.png similarity index 100% rename from www/IDEA_logo_500.png rename to images/IDEA_logo_500.png diff --git a/usa_reservoirs.png b/images/usa_reservoirs.png similarity index 100% rename from usa_reservoirs.png rename to images/usa_reservoirs.png diff --git a/ny_merged.Rds b/ny_merged.Rds deleted file mode 100644 index e5aa4b7..0000000 Binary files a/ny_merged.Rds and /dev/null differ diff --git a/ny_results.Rds b/ny_results.Rds deleted file mode 100644 index 397350f..0000000 Binary files a/ny_results.Rds and /dev/null differ diff --git a/ny_shp.Rds b/ny_shp.Rds deleted file mode 100644 index 9546dc0..0000000 Binary files a/ny_shp.Rds and /dev/null differ diff --git a/reservoirs_us.R b/reservoirs_us.R deleted file mode 100644 index 81f37e0..0000000 --- a/reservoirs_us.R +++ /dev/null @@ -1,277 +0,0 @@ -library(usmap) -library(ggplot2) -library(plotly) -library(tidyverse) -library(shinythemes) - -library(RColorBrewer) -library(sf) -library(raster) # problems installing `terra` -library(readr) -library(maps) -library(maptools) - -library(sp) -library(leaflet) -library(tigris) -library(stringr) - -#library(fec16) -library(fec12) -library(shiny) -library(htmltools) -library(shinybusy) -library(foreign) - -####### -### Setup for US map -reservoirs <- readRDS("reservoirs.Rds") -reservoirs_trim <- reservoirs %>% - dplyr::select("lat","lon"="long","dam_name","pv_annual_kWh", "prim_owner") - -test_data <- data.frame( - lon = reservoirs_trim$lon, - lat = reservoirs_trim$lat, - dam_name = reservoirs_trim$dam_name, - pv_annual_kWh = reservoirs_trim$pv_annual_kWh, - prim_owner = reservoirs_trim$prim_owner -) - -test_transformed <- usmap_transform(test_data) - -### Setup for NY map -reservoirs_NY <- readRDS("reservoirs_NY.Rds") - -new_york <- readRDS("new_york.Rds") - -Tract2District <- readRDS("Tract2District.Rds") -Tract2District_ny <- Tract2District %>% - filter(STATE == "NY") %>% - dplyr::select(GEOID, DISTRICT) - -new_york <- merge(new_york, Tract2District_ny, by="GEOID") - -ny_results <- readRDS("ny_results.Rds") - -### UI - -ui <- fluidPage( - titlePanel("Estimated Photovolatic Production for Floating PV"), - navbarPage(textOutput("input_text"),id = "mainpage", - tabPanel("State Estimated Production",value = "homepage", - selectInput(inputId = "state", - label = "Choose a state:", - choices = c("New York"="NY"), - multiple = FALSE), - sidebarLayout( - sidebarPanel(width = 2, - selectInput("district", "Select a district:", - c("1st" = "01", - "2nd" = "02", - "3rd" = "03", - "4th" = "04", - "5th" = "05", - "6th" = "06", - "7th" = "07", - "8th" = "08", - "9th" = "09", - "10th" = "10", - "11th" = "11", - "12th" = "12", - "13th" = "13", - "14th" = "14", - "15th" = "15", - "16th" = "16", - "17th" = "17", - "18th" = "18", - "19th" = "19", - "20th" = "20", - "21st" = "21", - "22nd" = "22", - "23rd" = "23", - "24th" = "24", - "25th" = "25", - "26th" = "26", - "27th" = "27" - ), - selected = "20",width = 150) - ), - mainPanel( - tags$p(tags$b("Click on a dot to view reservoir name, estimated PV production and census tract Low/moderate income percentage.")), - tags$p(tags$i("Select a congressional district (left) to highlight census tracts in that district.")), - leafletOutput("reservoir_map", height = "750"), - tags$p("Estimated photovoltaic production data provided by National Renewable Energy Laboratory (NREL); see: - Spencer, R. S., Macknick, J., Aznar, A., Warren, A., & Reese, M. O. (2018).", - tags$a("Floating photovoltaic systems: assessing the technical potential of photovoltaic - systems on man-made water bodies in the continental United States.", - href="https://pubs.acs.org/doi/abs/10.1021/acs.est.8b04735"), - "Environmental science & technology, 53(3), 1680-1689."), - tags$p("Estimated reservoir area obtained from US Army Corps of Engineers (USACE)"), - tags$p("Income data obtained from US Census"), - tags$p("Interactive visualization app created by the Rensselaer Institute for Data Exploration and Applications (IDEA)"), - img(src='IDEA_logo_500.png', align = "right", height=75) - - ) - ) - - ), - tabPanel("US Estimated Production", value ="us_page", - plotlyOutput("us_map") - ) - ) -) - -#### - -server <- function(input, output, session){ - output$input_text <- renderText(paste0("Selected state: ",input$state)) - - - ny_shp <- readRDS("ny_shp.Rds") - - ny_merged <- ny_shp %>% - st_transform(4326) %>% - inner_join(ny_results, by = c("DISTRICT" = "district")) - - output$us_map <- renderPlotly({ - p1 <- plot_usmap() + - geom_point(data = test_transformed, - aes(x = lon.1, y = lat.1, - size=pv_annual_kWh, - text = dam_name, - color = prim_owner)) + - labs(title = "Estimated Photovoltaic Production of US Reservoirs", - subtitle = "Source: NREL") + - theme(legend.position = "right") - - p2 <- ggplotly(p1, tooltip = c("dam_name","prim_owner")) - - m <- list( - l = 50, - r = 50, - b = 100, - t = 100, - pad = 4 - ) - - p2 %>% layout(autosize = F, - width = 1000, height = 1000, margin = m, - legend = list( - orientation = "h" - ) - ) - - -}) - - ### For NY Map - pal <- colorNumeric(palette = "Greys", domain = c(0, 1), reverse = FALSE) - - dam_colors <- brewer.pal(n = 5,name="Dark2") - - pal_dam <- colorFactor(dam_colors, - domain = c("Private", - "Local Government", - "State", - "Public Utility", - "Federal")) - - tag.map.title <- tags$style(HTML(" - .leaflet-control.map-title { - transform: translate(-50%,20%); - position: fixed !important; - left: 50%; - text-align: left; - padding-left: 10px; - padding-right: 10px; - background: rgba(255,255,255,0.75); - font-weight: bold; - font-size: 20px; - } -")) - - title <- tags$div( - tag.map.title, HTML("Reservoirs in New York by Census Tract") - ) - - output$reservoir_map <- renderLeaflet({ - - # TODO: Select state and district reactively; update reactively (ie leafletproxy()) - - new_york_cd <- new_york %>% filter(DISTRICT == input$district) - - leaflet(new_york_cd) %>% - # Background map - addTiles() %>% - # Census tract shapes and shading - addPolygons( - fillColor = new_york_cd$Lowmod_pct, - weight = 1, # 0 seems to speed it up - fillOpacity = 0.2, - color = "black" - ) %>% - # Centering - setView(lng = -75.37, lat = 42.98, zoom = 7) %>% - # Reservoir coloring legend - addLegend("topleft", - pal = pal_dam, - values = ~as.factor(reservoirs_NY$prim_owner), - title = "Reservoir Primary Owner Type", - opacity = 1) %>% - # Census tract legend - addLegend("topleft", - pal = pal, - values = new_york_cd$Lowmod_pct, - title = "Percentage Low or Medium Income", - opacity = 1) %>% - # Congressional district shapes - addPolygons( - data = ny_merged, - weight = 2, - fillOpacity = 0, - color = "green" - ) %>% - # Floating map title - addControl(title, position = "topleft", className="map-title") %>% - # Reservoir markers; must be last! - addCircleMarkers(data=reservoirs_NY, - weight = 2, - opacity = 1, - radius = 5, - fillOpacity = 1, - lng=reservoirs_NY$long, - lat=reservoirs_NY$lat, - color=~pal_dam(as.factor(reservoirs_NY$prim_owner)), - popup = paste0(reservoirs_NY$dam_name,"
", - "Primary Purpose: ", reservoirs_NY$prim_purpose, "
", - "Low/Mod Income Pct: ",100*reservoirs_NY$Lowmod_pct,"%
", - "Estimated Surface Area (USACE): ",reservoirs_NY$nid_area," acres
", - "Estimated PV Annual Production (NREL): ",reservoirs_NY$pv_annual_kWh," kWh
", - #"GEOID: ",reservoirs_NY$gid, - NULL - )) - - }) - - # Content of modal dialog - query_modal <- modalDialog( - title = "Welcome to the Floating Photovoltaic Reservoir Explorer", - "PLEASE NOTE: This application is the result of the efforts of students - and staff of the Rensselaer IDEA in collaboration with the Town of Cohoes, NY. - This is a prototype application and may not meet all of the standards one might - expect of a production commercial product.", - easyClose = F, - footer = tagList(actionButton("run", "Continue with the Floating PV Explorer")) - ) - - # Creates modal dialog - showModal(query_modal) - - # Removes modal - observeEvent(input$run, { - removeModal() - }) - -} - -shinyApp(ui, server) \ No newline at end of file