From 2891ade29880e484bb6b55d97b47b140c24ecdc7 Mon Sep 17 00:00:00 2001 From: dfaragon Date: Wed, 22 May 2024 13:58:09 -0700 Subject: [PATCH 1/8] updated campus-belonging helper code to match tables and map png names --- .DS_Store | Bin 6148 -> 6148 bytes app/.DS_Store | Bin 8196 -> 6148 bytes app/code/.DS_Store | Bin 0 -> 6148 bytes app/code/helper_code/campus-belonging.Rmd | 35 ++++++++++++---------- 4 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 app/code/.DS_Store diff --git a/.DS_Store b/.DS_Store index c2de99258358d0a4cbb325b6812e06b180a59cdf..3812b47f32ce2c40e6eecd37944339ca2484ea32 100644 GIT binary patch delta 37 tcmZoMXfc@J&&aVcU^g=($7CLsf1D}B$vH{+`8kZ6SidlBX6N|J4*=(r43Pi; delta 31 ncmZoMXfc@J&&a+pU^g=(`(z%Lf171lUolN=5Z=tr@s}R}qlyY^ diff --git a/app/.DS_Store b/app/.DS_Store index 3ac94782823c5f71e558764e5a28837d68b87907..f0840c5ed0cbfbb4e2f4ef7831b45f225159bded 100644 GIT binary patch delta 169 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGjUEV6q~50D9QTPiO6kFamtypw26qAJrrRCDE=5B~IP1S+ zV!Zi}=>OtLzxh#w0n&IeHqLD3z1f-f&5v*1?DSD0V$E@{PE;Zy2U+N10b)ZE?IN$G zjIOx}&44Ew(1?6`PaO)@tZjv5z%pPNunbrRECc@n1GuwAa<<(2s?|!%fMwvnWI%i$ zTx6j=t>;S1PX~ky0ibiJmI-CV0TSbC?P)z%T0+sMiXNDTG96+t1xLFp%%MH4=SnL$ zF$E{4M`k)gVRCffTxm|sQ`$<)fMsBv0TH|JAzJqlxp!9L_lU;SN8MW)(|0L_O+-~1 zQcQy<5$^^O4}ca2?lE%pr%Wh`&q0?s^{8*yeconw-X6sfj|XTM2RsL?FGe)*>*Hv< zV3G{=e7*+5C`{5??K{h4bJuouon5Ekyl$WHNjvq^ankfhFU8w4&ZFR>><7=o{-jg9 zeaPd~599tw0>WM&Ca+$EagR@$d>r=@iEXO}C-3At#nN>8aKG#}Y6r8jJFVCDAC%pL zdSf=rJ9qBge{|eAjm~2J0qa6y`U6Hc)cZnyL}{^ZgO4nQbY`;71Y()>J=pkk3R~)?cq*8~5Kl#p6vBsM z={py*sA6w9X7$b(`-d_1b=_Y>&b774A2PyUmKi8uRY&l~7CnWoV(uwc8Lf_#`DUQ< z25OC$?4f}uf?1BU5kU&Bf1jL<=Og>Yz~9pNL^9LGe)Pf0CB4W~_G#&qUEWJV=cdRjT$8T OLx7~g3d_J>W#AV&p&`Nm diff --git a/app/code/.DS_Store b/app/code/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f379bc6c89a5e7eb9582884b6c29495800e6a023 GIT binary patch literal 6148 zcmeHKyG{c!5S)b+k#J z=g~_Ln+J%!a86`|W=SO`)vCp?q%+xmkrfD~9N zaGT4$*Z&9lAN~K5q?Htq0#~JgZH|w}1D{m2b@e!}wT=Ev_ndFK8|Ojc5apN{<(LaE e$9IvGdClkC?}c+>&>0UpQ9lE&i%bgqw*o)0WEIi? literal 0 HcmV?d00001 diff --git a/app/code/helper_code/campus-belonging.Rmd b/app/code/helper_code/campus-belonging.Rmd index 854cb2b..de0b5ce 100644 --- a/app/code/helper_code/campus-belonging.Rmd +++ b/app/code/helper_code/campus-belonging.Rmd @@ -4,6 +4,7 @@ title: "Campus Belonging" ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) +library(shinydashboard) ``` ## What we need here: @@ -33,7 +34,9 @@ dashboardBody( # includeMarkdown("www/summary.md"), fluidRow( column(3, uiOutput("dynamicFilter")), + column(3, reactableOutput("table")) %>% withSpinner(color = "navy"), column(3, reactableOutput("table")) %>% withSpinner(color = "navy")) + )) ``` @@ -59,23 +62,23 @@ shinyServer(function(input, output) { # Render the correct table based on the input selection output$table <- renderReactable({ if(input$typeSelect == "Undergraduate" && input$yearSelect == "Overall") { - rt_cam_us_ug + us_ug } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2022") { - rt_cam_us_ug_ay2122 + us_ug_ay2122 } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2020") { - rt_cam_us_ug_ay1920 + us_ug_ay1920 } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2019") { - rt_cam_us_ug_ay1819 + us_ug_ay1819 } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2018") { - rt_cam_us_ug_ay1718 + us_ug_ay1718 } else if(input$typeSelect == "International" && input$intSelect == "Overall") { - rt_cam_i + i } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad 2022") { - rt_cam_i_ay2122 + i_ay2122 } else if(input$typeSelect == "International" && input$intSelect == "Undergrad 2020") { - rt_cam_i_ug_ay1920 + i_ug_ay1920 } else if(input$typeSelect == "Graduate") { - rt_cam_gr_ay2122 + gr_ay2122 } }) @@ -84,23 +87,23 @@ shinyServer(function(input, output) { if(input$typeSelect == "Undergraduate" && (is.null(input$yearSelect) || input$yearSelect == "Overall")) { return("Select year breakdown :)") } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2022") { - list(src = "maps/map_cam_b_us_ug_ay2122.png") + list(src = "maps/b_map_cam_us_ug_ay2122.png") } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2020") { - list(src = "maps/map_cam_b_us_ug_ay1920.png") + list(src = "maps/b_map_cam_us_ug_ay1920.png") } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2019") { - list(src = "maps/map_cam_b_us_ug_ay1819.png") + list(src = "maps/b_map_cam_us_ug_ay1819.png") } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2018") { - list(src = "maps/map_cam_b_us_ug_ay1718.png") + list(src = "maps/b_map_cam_us_ug_ay1718.png") } else if(input$typeSelect == "International" && input$intSelect == "Overall") { return("Select year breakdown :)") } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad 2022") { return(rt_cam_i_ay2122) - list(src = "maps/map_cam_b_i_ug_ay2122.png") + list(src = "maps/b_map_cam_i_ug_ay2122.png") } else if(input$typeSelect == "International" && input$intSelect == "Undergrad 2020") { return(rt_cam_i_ug_ay1920) - list(src = "maps/map_cam_b_i_ug_ay1920.png") + list(src = "maps/b_map_cam_i_ug_ay1920.png") } else if(input$typeSelect == "Graduate") { - list(src = "maps/map_cam_b_gr_ay2122.png") + list(src = "maps/b_map_cam_gr_ay2122.png") } }) From d3bd73d0d7df0ce930e61a6c148710231b100020 Mon Sep 17 00:00:00 2001 From: dfaragon Date: Wed, 22 May 2024 14:23:02 -0700 Subject: [PATCH 2/8] updated server shiny code with correct table and map files --- app/code/helper_code/campus-belonging.Rmd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/helper_code/campus-belonging.Rmd b/app/code/helper_code/campus-belonging.Rmd index de0b5ce..e1927fa 100644 --- a/app/code/helper_code/campus-belonging.Rmd +++ b/app/code/helper_code/campus-belonging.Rmd @@ -5,6 +5,8 @@ title: "Campus Belonging" ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) library(shinydashboard) +library(usethis) +use_git_config(user.name = "dfaragon", user.email = "dotz.da@gmail.com") ``` ## What we need here: From 1086af3d9e8c7f3af620be49005e155b4f9ef121 Mon Sep 17 00:00:00 2001 From: dfaragon Date: Wed, 5 Jun 2024 15:36:57 -0700 Subject: [PATCH 3/8] Update campus-belonging.Rmd --- app/code/helper_code/campus-belonging.Rmd | 340 +++++++++++++++++++--- 1 file changed, 304 insertions(+), 36 deletions(-) diff --git a/app/code/helper_code/campus-belonging.Rmd b/app/code/helper_code/campus-belonging.Rmd index e1927fa..8b39104 100644 --- a/app/code/helper_code/campus-belonging.Rmd +++ b/app/code/helper_code/campus-belonging.Rmd @@ -15,6 +15,7 @@ use_git_config(user.name = "dfaragon", user.email = "dotz.da@gmail.com") - filter apply to both maps - maps are already extracted in "maps" folder: i have the standardized code for this already created so let me know if you are doing this piece -anwesha - hover for text (see NPS example) +- just heat maps? ## Brian's Code ```{r} @@ -26,6 +27,17 @@ use_git_config(user.name = "dfaragon", user.email = "dotz.da@gmail.com") ``` +## Data Tables +```{r} +# # bar plots +# tables_bp <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_bp.rds") +# # tree maps +# tables_tm <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_tm.rds") +# # reactable tables +# tables_rt <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_rt.rds") + +``` + ## UI draft ```{r} @@ -36,10 +48,9 @@ dashboardBody( # includeMarkdown("www/summary.md"), fluidRow( column(3, uiOutput("dynamicFilter")), - column(3, reactableOutput("table")) %>% withSpinner(color = "navy"), - column(3, reactableOutput("table")) %>% withSpinner(color = "navy")) - - )) + column(3, reactableOutput("table")) %>% withSpinner(color = "navy")))) + # column(3, inclusive_bar_fun("campusImage")) %>% withSpinner(color = +# )) ``` @@ -49,12 +60,13 @@ shinyServer(function(input, output) { # Dynamic UI for additional filters output$dynamicFilter <- renderUI({ - if(input$typeSelect == "Undergraduate") { + if(input$typeSelect == "US Undergraduate") { # added US for clarity selectInput("yearSelect", "Select Year:", choices = c("2018", "2019", "2020", "2022", "Overall")) } else if(input$typeSelect == "International") { selectInput("intSelect", "Select Category:", choices = c("Overall", "Undergrad and Grad 2022", "Undergrad 2020")) + # Here, do I add an option for campus inclusiveness after choosing the hear and needing to choose all years, 4th-year, 3-rd year etc. } else { return() } @@ -62,53 +74,309 @@ shinyServer(function(input, output) { # Render the correct table based on the input selection +######## campus summary tables ######## + ## do not change this is your original example and is correct ## output$table <- renderReactable({ if(input$typeSelect == "Undergraduate" && input$yearSelect == "Overall") { - us_ug + reactable_fun(us_ug) } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2022") { - us_ug_ay2122 + reactable_fun(us_ug_ay2122) } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2020") { - us_ug_ay1920 + reactable_fun(us_ug_ay1920) } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2019") { - us_ug_ay1819 + reactable_fun(us_ug_ay1819) } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2018") { - us_ug_ay1718 + reactable_fun(us_ug_ay1718) } else if(input$typeSelect == "International" && input$intSelect == "Overall") { - i + reactable_fun(i) } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad 2022") { - i_ay2122 + reactable_fun(i_ay2122) } else if(input$typeSelect == "International" && input$intSelect == "Undergrad 2020") { - i_ug_ay1920 + reactable_fun(i_ug_ay1920) } else if(input$typeSelect == "Graduate") { - gr_ay2122 + reactable_fun(gr_ay2122) } }) - output$campusImage <- renderImage({ + +######## campus heat maps ######## + output$campusHeatMaps <- renderImage({ + if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "AllYears") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "4th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122_c2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "3th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122_c2021.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122_c2021.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "2th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122_c1920.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122_c1920.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "1th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122_c1819.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122_c1819.png", style = "display:inline-block;") + ) + #### spring 2020, 2021 was skipped + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "1st-through-5th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1920.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1920.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "4th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1920.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1920.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "3th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1819.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1819.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "2th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1718.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1718.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "1th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1617.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1617.png", style = "display:inline-block;") + ) + #### spring 2019 + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1st-through-4th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122_c2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "4th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "3th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "2th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") + ) + #### spring 2018 + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2018" && input$yearSelect == "1st-through-3th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1718.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1718.png", style = "display:inline-block;") + ) + ### international + } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad Spring 2022") { + tags$div( + tags$img(src = "maps/map_cam_b_i_ay2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_i_ay2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "International" && input$intSelect == "Undergrad Spring 2020") { + tags$div( + tags$img(src = "maps/map_cam_db_i_ug_ay1920.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_i_ug_ay1920.png", style = "display:inline-block;") + ) + ### graduate student + } else if(input$typeSelect == "Graduate") { # no other option needed here + tags$div( + tags$img(src = "maps/map_cam_b_gr_ay2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_gr_ay2122.png", style = "display:inline-block;") + ) + } + }) + +}) + + +# first version + # output$campusImage <- renderImage({ # Decide which table to render after the data has been effectively filtered based on the following filters - if(input$typeSelect == "Undergraduate" && (is.null(input$yearSelect) || input$yearSelect == "Overall")) { - return("Select year breakdown :)") - } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2022") { - list(src = "maps/b_map_cam_us_ug_ay2122.png") - } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2020") { - list(src = "maps/b_map_cam_us_ug_ay1920.png") - } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2019") { - list(src = "maps/b_map_cam_us_ug_ay1819.png") - } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2018") { - list(src = "maps/b_map_cam_us_ug_ay1718.png") + # if(input$typeSelect == "US Undergraduate" && (is.null(input$yearSelect) || input$yearSelect == "Overall")) { + # return("Select year breakdown :)") + # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2022") { + # list(src = "maps/b_map_cam_us_ug_ay2122.png") + # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2020") { + # list(src = "maps/b_map_cam_us_ug_ay1920.png") + # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2019") { + # list(src = "maps/b_map_cam_us_ug_ay1819.png") + # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2018") { + # list(src = "maps/b_map_cam_us_ug_ay1718.png") + # } else if(input$typeSelect == "International" && input$intSelect == "Overall") { + # return("Select year breakdown :)") + # } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad 2022") { + # return(rt_cam_i_ay2122) + # list(src = "maps/b_map_cam_i_ug_ay2122.png") + # } else if(input$typeSelect == "International" && input$intSelect == "Undergrad 2020") { + # return(rt_cam_i_ug_ay1920) + # list(src = "maps/b_map_cam_i_ug_ay1920.png") + # } else if(input$typeSelect == "Graduate") { + # list(src = "maps/b_map_cam_gr_ay2122.png") + # } + # }) + + +######## campus belong tree plots ######## +#### may be computationally expensive + output$campusTreeMaps <- renderPlotly({ + # Ensure yearSelect and classSelect are not null + if (is.null(input$yearSelect) || is.null(input$classSelect) || input$yearSelect == "Overall") { + return(NULL) + } + + # Mapping the years to their codes + yearMapping <- list( + "Spring 2018" = "ay1718", + "Spring 2019" = "ay1819", + "Spring 2020" = "ay1920", + "Spring 2021" = "ay2021", + "Spring 2022" = "ay2122" + ) + + # Mapping the class to their codes + classMapping <- list( + "1st-Year" = "c1", + "2nd-Year" = "c2", + "3rd-Year" = "c3", + "4th-Year" = "c4" + ) + + yearCode <- yearMapping[[input$yearSelect]] + classCode <- classMapping[[input$classSelect]] + + # Generate the data for the tree map + dat <- your_data_preparation_function(yearCode, classCode) # Assuming you have a function for this + + # Call the inclusive_tree_fun function to generate the tree map + tree_map <- inclusive_tree_fun(dat) + + # Return the plotly object + tree_map + }) + + + +#### code if the computational cost of creating the maps is too much and we need to use already developed images +# output$campusImage <- renderImage({ +# # Ensure yearSelect and classSelect are not null +# if (is.null(input$yearSelect) || is.null(input$classSelect) || input$yearSelect == "Overall") { +# return("Select year breakdown :)") +# } +# +# # Mapping the years to their codes +# yearMapping <- list( +# "Spring 2018" = "ay1718", +# "Spring 2019" = "ay1819", +# "Spring 2020" = "ay1920", +# "Spring 2021" = "ay2021", +# "Spring 2022" = "ay2122" +# ) +# +# # Mapping the class to their codes +# classMapping <- list( +# "AllYears" = "c_all", # would require that those without class add "c_all" in png image name +# "1st-Year" = "c2122", +# "2nd-Year" = "c2021", +# "3rd-Year" = "c1920", +# "4th-Year" = "c1819" +# ) +# +# yearCode <- yearMapping[[input$yearSelect]] +# classCode <- classMapping[[input$classSelect]] +# +# belongImage <- "" +# dontBelongImage <- "" +# +# # Constructing the image paths based on the typeSelect +# if (input$typeSelect == "US Undergraduate") { +# belongImage <- paste0("maps/map_cam_b_us_ug_", yearCode, "_", classCode, ".png") +# dontBelongImage <- paste0("maps/map_cam_db_us_ug_", yearCode, "_", classCode, ".png") +# } else if (input$typeSelect == "International") { +# belongImage <- paste0("maps/map_cam_b_i_", yearCode, "_", classCode, ".png") +# dontBelongImage <- paste0("maps/map_cam_db_i_", yearCode, "_", classCode, ".png") +# } else if (input$typeSelect == "Graduate") { +# belongImage <- paste0("maps/map_cam_b_gr_", yearCode, "_", classCode, ".png") +# dontBelongImage <- paste0("maps/map_cam_db_gr_", yearCode, "_", classCode, ".png") +# } +# +# # Rendering both images +# tags$div( +# tags$img(src = belongImage, style = "display:inline-block;margin-right:10px;"), +# tags$img(src = dontBelongImage, style = "display:inline-block;") +# ) +# }) +# } + + +######## campus bar plots ######## + ## good ## + output$campusBarPlots <- renderReactable({ + if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Overall") { + reactable_fun(cam_us_ug) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "AllYears") { + inclusive_bar_fun(cam_us_ug_ay2122) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "4th-Year") { + inclusive_bar_fun(cam_us_ug_ay2122_c2122) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "3th-Year") { + inclusive_bar_fun(cam_us_ug_ay2122_c2021) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "2th-Year") { + inclusive_bar_fun(cam_us_ug_ay2122_c1920) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "1th-Year") { + inclusive_bar_fun(cam_us_ug_ay2122_c1819) + #### spring 2020, 2021 was skipped + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "1st-through-5th-Year") { + inclusive_bar_fun(cam_us_ug_ay1920) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "4th-Year") { + inclusive_bar_fun(us_ug_ay1920_1920) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "3th-Year") { + inclusive_bar_fun(us_ug_ay1920_c1819) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "2th-Year") { + inclusive_bar_fun(us_ug_ay1920_c1718) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "1th-Year") { + inclusive_bar_fun(us_ug_ay2122_c1617) + #### spring 2019 + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1st-through-4th-Year") { + inclusive_bar_fun(cam_us_ug_ay1819) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "4th-Year") { + inclusive_bar_fun(us_ug_ay1819_1819) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "3th-Year") { + inclusive_bar_fun(us_ug_ay1819_c1718) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "2th-Year") { + inclusive_bar_fun(us_ug_ay1819_c1617) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1th-Year") { + inclusive_bar_fun(us_ug_ay1819_c1516) + #### spring 2018 + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2018" && input$yearSelect == "1st-through-3th-Year") { + inclusive_bar_fun(cam_us_ug_ay1718) } else if(input$typeSelect == "International" && input$intSelect == "Overall") { - return("Select year breakdown :)") - } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad 2022") { - return(rt_cam_i_ay2122) - list(src = "maps/b_map_cam_i_ug_ay2122.png") - } else if(input$typeSelect == "International" && input$intSelect == "Undergrad 2020") { - return(rt_cam_i_ug_ay1920) - list(src = "maps/b_map_cam_i_ug_ay1920.png") - } else if(input$typeSelect == "Graduate") { - list(src = "maps/b_map_cam_gr_ay2122.png") + inclusive_bar_fun(i) # where is this one?? + } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad Spring 2022") { + inclusive_bar_fun(cam_i_ay2122) + } else if(input$typeSelect == "International" && input$intSelect == "Undergrad Spring 2020") { + inclusive_bar_fun(cam_i_ug_ay1920) + } else if(input$typeSelect == "Graduate") { # no other option needed here + inclusive_bar_fun(cam_gr_ay2122) } }) - -}) + + ``` From e447230966219b407e08945132ad5efe642de185 Mon Sep 17 00:00:00 2001 From: dfaragon Date: Wed, 5 Jun 2024 15:43:14 -0700 Subject: [PATCH 4/8] Merge branch 'main' of https://github.com/dfaragon/place-based-belonging.git #Conflicts: # .DS_Store # app/.DS_Store # app/code/.DS_Store # app/code/helper_code/campus-belonging.Rmd # app/www/maps/.DS_Store --- app/.gitignore | 1 + app/code/.DS_Store~HEAD | Bin 0 -> 6148 bytes app/code/.gitignore | 1 + app/code/helper_code/campus-belonging.Rmd | 12 ++++++ app/www/about.md | 43 ++++++++++++++++++++++ app/www/maps/.DS_Store~HEAD | Bin 0 -> 6148 bytes 6 files changed, 57 insertions(+) create mode 100644 app/.gitignore create mode 100644 app/code/.DS_Store~HEAD create mode 100644 app/code/.gitignore create mode 100644 app/www/about.md create mode 100644 app/www/maps/.DS_Store~HEAD diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/app/code/.DS_Store~HEAD b/app/code/.DS_Store~HEAD new file mode 100644 index 0000000000000000000000000000000000000000..f379bc6c89a5e7eb9582884b6c29495800e6a023 GIT binary patch literal 6148 zcmeHKyG{c!5S)b+k#J z=g~_Ln+J%!a86`|W=SO`)vCp?q%+xmkrfD~9N zaGT4$*Z&9lAN~K5q?Htq0#~JgZH|w}1D{m2b@e!}wT=Ev_ndFK8|Ojc5apN{<(LaE e$9IvGdClkC?}c+>&>0UpQ9lE&i%bgqw*o)0WEIi? literal 0 HcmV?d00001 diff --git a/app/code/.gitignore b/app/code/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/app/code/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/app/code/helper_code/campus-belonging.Rmd b/app/code/helper_code/campus-belonging.Rmd index 8b39104..abc2279 100644 --- a/app/code/helper_code/campus-belonging.Rmd +++ b/app/code/helper_code/campus-belonging.Rmd @@ -48,14 +48,22 @@ dashboardBody( # includeMarkdown("www/summary.md"), fluidRow( column(3, uiOutput("dynamicFilter")), +<<<<<<< HEAD column(3, reactableOutput("table")) %>% withSpinner(color = "navy")))) # column(3, inclusive_bar_fun("campusImage")) %>% withSpinner(color = # )) +======= + column(3, reactableOutput("table")) %>% withSpinner(color = "navy")) + #add map tabItem + )) +>>>>>>> main ``` ## Server draft ```{r} +# add reactable_fun() is here + shinyServer(function(input, output) { # Dynamic UI for additional filters @@ -66,7 +74,11 @@ shinyServer(function(input, output) { } else if(input$typeSelect == "International") { selectInput("intSelect", "Select Category:", choices = c("Overall", "Undergrad and Grad 2022", "Undergrad 2020")) +<<<<<<< HEAD # Here, do I add an option for campus inclusiveness after choosing the hear and needing to choose all years, 4th-year, 3-rd year etc. +======= + #add whichever remaining filter (see pbb HTML) +>>>>>>> main } else { return() } diff --git a/app/www/about.md b/app/www/about.md new file mode 100644 index 0000000..e259d7d --- /dev/null +++ b/app/www/about.md @@ -0,0 +1,43 @@ +# Who is SWaSI? + +The [Student Wellbeing and Success Initiative](https://uoregon-my.sharepoint.com/:u:/g/personal/clark13_uoregon_edu/EY4zzGdo3o9ImgpS89tM2wAB4CrNAqmPyAxDAZQ-mNuzJw){target="_blank" style="color: #DF63A4"} is: + +- an ongoing, multicohort, longitudinal research program designed to holistically understand institutional inputs to undergraduate students’ wellbeing and success across the college experience +- an educational program designed to equitably improve wellbeing and success outcomes, particularly among historically marginalized populations (e.g., first-generation students, Black students) +- an assessment and evaluation program designed to gauge whether various programmatic activities, including but not limited to the ones internal to the Initiative itself, are meeting their stated goals + +Better understanding better informs us, affording opportunities to improve institutional practices that equitably support students’ learning and development and foster their achievement and persistence. Unlike many for-profit companies, which use data to sell people, this is a strategy that uses data to [empower](#){style="color: #11E8FF"} people. + +The Student Wellbeing and Success Initiative is led by Brian Clark, Assistant Director of the [Office of Assessment and Research](https://studentlife.uoregon.edu/research){target="_blank" style="color: #DF63A4"} in the [Division of Student Life](https://studentlife.uoregon.edu/){target="_blank" style="color: #DF63A4"}. It is supported primarily by the Office of the Vice President for Student Life with integral support from units of the Division of Student Life -- the [Department of Physical Education and Recreation](https://rec.uoregon.edu/){target="_blank" style="color: #DF63A4"}, the [Erb Memorial Union](https://emu.uoregon.edu/){target="_blank" style="color: #DF63A4"}, and the [Office of the Dean of Students](https://dos.uoregon.edu/){target="_blank" style="color: #DF63A4"} -- and across campus from many and varied units in [Global Engagement](https://international.uoregon.edu/){target="_blank" style="color: #DF63A4"}, the [Office of the Provost](https://provost.uoregon.edu/){style="color: #DF63A4"}, [Student Services and Enrollment Management](https://ssem.uoregon.edu/){target="_blank" style="color: #DF63A4"}, [UO Libraries](https://library.uoregon.edu/){target="_blank" style="color: #DF63A4"}, and [Undergraduate Education and Student Success](https://uess.uoregon.edu/){target="_blank" style="color: #DF63A4"}. + +
+ +# What is this Document for? + +The purposes of this document are: + +1. to conduct a comprehensive analysis of place-based belonging data +2. to provide a general reference and resource tool for higher education professionals who do things and make decisions about things that affect students (many of those things are tied to or rooted in physical places) +3. to describe the development of methods used to generate place-based belonging data + +[This document is currently under construction and is in a "good enough for now" state](#){style="color: #11E8FF"}. It will be incrementally updated through Summer 2023, which will include adding Spring 2023 data. At that point, it will be considered complete, because we intend to augment methods dramatically the following year. Forthcoming sections include an overall summary, two content sections, and the supplemental method section. Forthcoming features include alternative text for plots and images and hover text for treemaps. + +## What is Place-Based Belonging? + +Over the last several years, we have been incrementally exploring the concept of place-based belonging: the idea that people’s affinity for physical places, or lack thereof, is intertwined with their sense of whether they fit in socially. Theoretically, it is a special case of the environmental psychology concept of place attachment ([Altman & Low, 1992](https://link.springer.com/chapter/10.1007/978-1-4684-8753-4_1){target="_blank" style="color: #DF63A4"}), with conceptual focus on the place dimension over the person or process dimensions ([Scannell & Gifford, 2010](https://uoregon-my.sharepoint.com/:b:/g/personal/clark13_uoregon_edu/EUOwgiMvl5pKonwqByWz8BoBkjCnPQk0VAw9mm1fzn3XfQ?e=WW9q1Z){target="_blank" style="color: #DF63A4"}) and content focus on social meanings with which places are imbued as a subset of the general affective associations people have with places. Methodologically, it departs significantly from the psychometric approach of much place attachment research (e.g., [Williams, 2014](https://uoregon-my.sharepoint.com/:b:/g/personal/clark13_uoregon_edu/EVGZxfZPNRlEoofpQI9UQz4BreUZgn5Z-W0Z7gVMNK7fdQ?e=xTznoC){target="_blank" style="color: #DF63A4"}; [Williams & Vaske, 2003](https://uoregon-my.sharepoint.com/:b:/g/personal/clark13_uoregon_edu/EVXdi_qf-_hPpRc_iruUoNwBJ1ma0fuw3ZHknWZWW2YAXQ?e=pVPMkt){target="_blank" style="color: #DF63A4"}), aligning more closely with cultural mapping. Cultural mapping is an interdisciplinary field broadly tied together by a mode of inquiry and general methodology that reckons with documenting a community's place-based features and assets for a wide range of purposes. See [Duxbury et al. (2015)](https://uoregon-my.sharepoint.com/:b:/g/personal/clark13_uoregon_edu/EQSU3UqGrw1GpScojaHKFVUBLiH2uuzMOtTlFmkpMoEr6w?e=jE9T38){target="_blank" style="color: #DF63A4"} for an introduction and the [whole book](https://www.routledge.com/Cultural-Mapping-as-Cultural-Inquiry/Duxbury-Garrett-Petts-MacLennan/p/book/9780367599003){target="_blank" style="color: #DF63A4"} for varied perspectives. Place-based belonging, specifically, has roots in humanistic and cultural geography traditions, which feed into cultural mapping, and is depicted by a kind of symbol mapping ([Soini, 2001](https://uoregon-my.sharepoint.com/:b:/g/personal/clark13_uoregon_edu/EVIw9hlo0LdGkCrxUpVFoYwBg__H3LRwrnGmUAavpQ1pRg?e=JyQV4u){style="color: #DF63A4"}). + +Adapting methods from [Pitcher & Royal (2016)](https://uoregon-my.sharepoint.com/:b:/g/personal/clark13_uoregon_edu/ETDssdQ-bW1LsSA_db4aaVgBd_vO02wIffeQ_AqgQ3TgwQ?e=yBVY5o){target="_blank" style="color: #DF63A4"}, we ask students to click up to three places on a campus map they feel like they “belong, fit in, are connected, are accepted, etc.,” and separately, to click up to three places they feel like they "[do not](#){style="color: #11E8FF"} belong, [do not](#){style="color: #11E8FF"} fit in, are [dis](#){style="color: #11E8FF"}connected, are [not](#){style="color: #11E8FF"} accepted, etc.” After clicking "belong" and "don't belong" places on a campus map, we follow up about select places to try and understand more about them. Generally, we ask students to describe in text why they feel the ways they do about the places. A unique aspect of follow-up involves delving into the Erb Memorial Union (EMU), which is a compact set of places, which cannot be disaggregated given a campus map and which form a unified place we call the EMU. If a student clicks on the EMU at the campus level, we follow up with a map of the EMU and ask them to click on places within the EMU they feel like they belong and don't belong, and then ask them to describe why. (Map and follow-up methods have varied over the years of development. See [Supplemental Method](#supmeth){style="color: #DF63A4"} for more details.) + +The methods above generate data that allow us to do several things: + +- describe a place and rank-order multiple places in terms of belong and don't belong sentiments +- describe a place and rank-order multiple places in terms of inclusiveness, which is a combination of both belong and don't belong sentiments +- disaggregate a place's inclusiveness by demographics +- explore why places have belong or don't belong sentiments associated with them +- describe how places relate to each other through belong and don't belong sentiments + +Application Notes: + +- The application is created using the [**periscope**](https://github.com/neuhausi/periscope) package. Periscope was originally developed as the core Shiny component for bioinformatics and systems biology analysis applications. It provides a predefined but flexible template for new Shiny applications with a default dashboard layout, three locations for user alerts, a nice busy indicator and logging features. One of the most important features of the shiny applications created with this framework is the separation by file of functionality that exists in one of the three shiny scopes: global, server-global, and server-local. The framework forces application developers to consciously consider scoping in Shiny applications by making scoping distinctions very clear without interfering with normal application development. Scoping consideration is important for performance and scaling, which is critical when working with large datasets and/or across many users. In addition to providing a template application, the framework also contains a number of convenient modules: a (multi)file download button module and a downloadable table module for example. + +*This application is developed and maintained by Anwesha Guha. This is a work in progress. v2* diff --git a/app/www/maps/.DS_Store~HEAD b/app/www/maps/.DS_Store~HEAD new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Tue, 11 Jun 2024 08:54:43 -0700 Subject: [PATCH 5/8] update campus-belonging --- app/code/helper_code/campus-belonging.Rmd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/helper_code/campus-belonging.Rmd b/app/code/helper_code/campus-belonging.Rmd index abc2279..4119f59 100644 --- a/app/code/helper_code/campus-belonging.Rmd +++ b/app/code/helper_code/campus-belonging.Rmd @@ -74,8 +74,12 @@ shinyServer(function(input, output) { } else if(input$typeSelect == "International") { selectInput("intSelect", "Select Category:", choices = c("Overall", "Undergrad and Grad 2022", "Undergrad 2020")) +<<<<<<< HEAD <<<<<<< HEAD # Here, do I add an option for campus inclusiveness after choosing the hear and needing to choose all years, 4th-year, 3-rd year etc. +======= + #add whichever remaining filter (see pbb HTML) +>>>>>>> main ======= #add whichever remaining filter (see pbb HTML) >>>>>>> main From ebacf6030afde30200c9719b58432ccb87df305f Mon Sep 17 00:00:00 2001 From: dfaragon Date: Tue, 25 Jun 2024 14:02:07 -0700 Subject: [PATCH 6/8] Update campus-belonging.Rmd --- app/code/helper_code/campus-belonging.Rmd | 351 +++++++++++++++------- 1 file changed, 238 insertions(+), 113 deletions(-) diff --git a/app/code/helper_code/campus-belonging.Rmd b/app/code/helper_code/campus-belonging.Rmd index 2d98ebe..3f92891 100644 --- a/app/code/helper_code/campus-belonging.Rmd +++ b/app/code/helper_code/campus-belonging.Rmd @@ -1,33 +1,227 @@ --- title: "Campus Belonging" --- - ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) library(shinydashboard) library(usethis) use_git_config(user.name = "dfaragon", user.email = "dotz.da@gmail.com") ``` - ## What we need here: - - campus maps, broken into "belong" on top and "don't belong" on bottom - filter apply to both maps - maps are already extracted in "maps" folder: i have the standardized code for this already created so let me know if you are doing this piece -anwesha - hover for text (see NPS example) -- just heat maps? - +- just heat maps? ## Brian's Code ```{r} - -``` - -## Standardized -```{r} - +library(reactable) +library(htmltools) +library(treemapify) +#function for interactive reactables +reactable_fun<- function(dat) { + options( + reactable.theme = reactableTheme( + color = "hsl(233, 9%, 87%)", + backgroundColor = "hsl(233, 9%, 19%)", + borderColor = "hsl(233, 9%, 22%)", + stripedColor = "hsl(233, 12%, 22%)", + highlightColor = "hsl(233, 12%, 24%)", + inputStyle = list(backgroundColor = "hsl(233, 9%, 25%)"), + selectStyle = list(backgroundColor = "hsl(233, 9%, 25%)"), + pageButtonHoverStyle = list(backgroundColor = "hsl(233, 9%, 25%)"), + pageButtonActiveStyle = list(backgroundColor = "hsl(233, 9%, 28%)") + ) + ) + rt<- dat %>% + reactable( + ., + groupBy = "agg_place", + showPageSizeOptions = T, + paginateSubRows = T, + defaultSorted = c("agg_place", "full_place"), + sortable = T, + showSortable = T, + striped = T, + highlight = T, + bordered = T, + defaultColDef = colDef( + vAlign = "center", + headerVAlign = "bottom" + ), + columns = list( + agg_place = colDef( + name = "Aggregated Place", + filterable = T, + align = "left", + minWidth = 240 + ), + full_place = colDef( + name = "Place", + align = "left", + minWidth = 215 + ), + n_b = colDef( + aggregate = "sum", + align = "center", + format = colFormat(separators = T, digits = 0), + html = T, + header = JS( + 'function(column) { + return `
n
` + "Belong" + }' + ) + ), + n_db = colDef( + aggregate = "sum", + align = "center", + format = colFormat(separators = T, digits = 0), + html = T, + header = JS( + 'function(column) { + return `
n
` + "Don\'t" + + "
Belong" + }' + ) + ), + perc_click_b = colDef( + aggregate = "sum", + align = "center", + format = colFormat(percent = T, digits = 1), + html = T, + header = JS( + 'function(column) { + return "Click" + "
Belong" + }' + ) + ), + perc_click_db = colDef( + aggregate = "sum", + align = "center", + format = colFormat(percent = T, digits = 1), + html = T, + header = JS( + 'function(column) { + return "Click" + "
Don\'t" + "
Belong" + }' + ) + ), + perc_stud_b = colDef( + aggregate = "sum", + align = "center", + format = colFormat(percent = T, digits = 1), + html = T, + header = JS( + 'function(column) { + return "Student" + "
Belong" + }' + ) + ), + perc_stud_db = colDef( + aggregate = "sum", + align = "center", + format = colFormat(percent = T, digits = 1), + html = T, + header = JS( + 'function(column) { + return "Student" + "
Don\'t" + "
Belong" + }' + ) + ), + incl = colDef( + aggregate = "mean", + name = "Inclusive", + align = "center", + format = colFormat(percent = T, digits = 1) + ) + ) + ) + return(rt) +} +#function for inclusiveness treemaps +inclusive_tree_fun<- function(dat) { + df<- dat + cp<- as.vector( + if_else(df$incl > 75, "#30313A", "#FCFFA4") + ) + plot<- dat %>% + ggplot( + ., + aes( + area = tot, + fill = incl, + label = place + ) + ) + + geom_treemap() + + geom_treemap_text( + place = "center", + grow = T, + reflow = T, + color = cp + ) + + scale_fill_viridis_c( + name = "Inclusiveness", + option = "inferno", + limits = c(0, 100) + ) + + theme( + panel.background = element_rect(fill = "#30313A"), + plot.background = element_rect(color = "#30313A", fill = "#30313A"), + legend.background = element_rect(fill = "#30313A"), + legend.title = element_text(color = "#FCFFA4"), + legend.text = element_text(color = "#FCFFA4"), + plot.margin = margin(0.5, 0.5, 0.5, 0.5, "cm") + #top, right, bottom, left, units + ) + return(plot) +} +#function for inclusiveness bar plots +inclusive_bar_fun<- function(dat, b_cp, e_cp) { + plot<- dat %>% + ggplot( + ., + aes( + x = agg_place, + y = incl, + fill = agg_place + ) + ) + + geom_bar( + stat = "identity", + position = "dodge" + ) + + xlab("") + + ylab("Inclusiveness") + + scale_y_continuous( + breaks = c(0, 25, 50, 75, 100), + limits = c(0, 125) + ) + + scale_fill_viridis_d( + option = "inferno", + begin = b_cp, + end = e_cp + ) + + coord_flip() + + geom_text( + aes(label = sprintf("%0.1f", incl)), + hjust = -0.5, + size = 5, + color = "#FCFFA4" + ) + + guides(fill = "none") + + theme( + panel.background = element_rect(fill = "#30313A"), + plot.background = element_rect(color = "#30313A", fill = "#30313A"), + panel.grid = element_blank(), + axis.title = element_text(size = 13, color = "#FCFFA4", hjust = 0.375), + axis.text = element_text(size = 12, color = "#FCFFA4"), + axis.ticks.y = element_blank() + ) + return(plot) +} ``` - -## Data Tables +## Data Tables ```{r} # # bar plots # tables_bp <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_bp.rds") @@ -35,67 +229,39 @@ use_git_config(user.name = "dfaragon", user.email = "dotz.da@gmail.com") # tables_tm <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_tm.rds") # # reactable tables # tables_rt <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_rt.rds") - ``` - - ## UI draft ```{r} dashboardBody( - tabItem(tabName = "table", - + tabItem(tabName = "table", # summary section - # includeMarkdown("www/summary.md"), + # includeMarkdown("www/summary.md"), fluidRow( column(3, uiOutput("dynamicFilter")), -<<<<<<< HEAD - column(3, reactableOutput("table")) %>% withSpinner(color = "navy")))) - # column(3, inclusive_bar_fun("campusImage")) %>% withSpinner(color = -# )) -======= - column(3, reactableOutput("table")) %>% withSpinner(color = "navy")) + column(3, reactableOutput("table")) %>% withSpinner(color = "navy")), + column(3, reactableOutput("table")) %>% withSpinner(color = "navy") #, #add map tabItem )) ->>>>>>> main ``` - - ## Server draft ```{r} # add reactable_fun() is here - shinyServer(function(input, output) { - # Dynamic UI for additional filters output$dynamicFilter <- renderUI({ if(input$typeSelect == "US Undergraduate") { # added US for clarity - selectInput("yearSelect", "Select Year:", + selectInput("yearSelect", "Select Year:", choices = c("2018", "2019", "2020", "2022", "Overall")) } else if(input$typeSelect == "International") { - selectInput("intSelect", "Select Category:", + selectInput("intSelect", "Select Category:", choices = c("Overall", "Undergrad and Grad 2022", "Undergrad 2020")) -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - # Here, do I add an option for campus inclusiveness after choosing the hear and needing to choose all years, 4th-year, 3-rd year etc. -======= - #add whichever remaining filter (see pbb HTML) ->>>>>>> main -======= - #add whichever remaining filter (see pbb HTML) ->>>>>>> main -======= - #add whichever remaining filter (see pbb HTML) ->>>>>>> e02c7eace3696a175e74d0b09ea47eae790a3956 } else { return() } }) - - - # Render the correct table based on the input selection -######## campus summary tables ######## - ## do not change this is your original example and is correct ## +########################### +## CAMPUS SUMMARY TABLES ## +########################### output$table <- renderReactable({ if(input$typeSelect == "Undergraduate" && input$yearSelect == "Overall") { reactable_fun(us_ug) @@ -117,9 +283,9 @@ shinyServer(function(input, output) { reactable_fun(gr_ay2122) } }) - - -######## campus heat maps ######## +###################### +## CAMPUS HEAT MAPS ## +###################### output$campusHeatMaps <- renderImage({ if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "AllYears") { tags$div( @@ -223,45 +389,16 @@ shinyServer(function(input, output) { ) } }) - }) - - -# first version - # output$campusImage <- renderImage({ - # Decide which table to render after the data has been effectively filtered based on the following filters - # if(input$typeSelect == "US Undergraduate" && (is.null(input$yearSelect) || input$yearSelect == "Overall")) { - # return("Select year breakdown :)") - # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2022") { - # list(src = "maps/b_map_cam_us_ug_ay2122.png") - # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2020") { - # list(src = "maps/b_map_cam_us_ug_ay1920.png") - # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2019") { - # list(src = "maps/b_map_cam_us_ug_ay1819.png") - # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2018") { - # list(src = "maps/b_map_cam_us_ug_ay1718.png") - # } else if(input$typeSelect == "International" && input$intSelect == "Overall") { - # return("Select year breakdown :)") - # } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad 2022") { - # return(rt_cam_i_ay2122) - # list(src = "maps/b_map_cam_i_ug_ay2122.png") - # } else if(input$typeSelect == "International" && input$intSelect == "Undergrad 2020") { - # return(rt_cam_i_ug_ay1920) - # list(src = "maps/b_map_cam_i_ug_ay1920.png") - # } else if(input$typeSelect == "Graduate") { - # list(src = "maps/b_map_cam_gr_ay2122.png") - # } - # }) - - -######## campus belong tree plots ######## -#### may be computationally expensive +####################### +## CAMPUS TREE PLOTS ## +####################### +#### may be computationally expensive output$campusTreeMaps <- renderPlotly({ # Ensure yearSelect and classSelect are not null if (is.null(input$yearSelect) || is.null(input$classSelect) || input$yearSelect == "Overall") { return(NULL) } - # Mapping the years to their codes yearMapping <- list( "Spring 2018" = "ay1718", @@ -270,7 +407,6 @@ shinyServer(function(input, output) { "Spring 2021" = "ay2021", "Spring 2022" = "ay2122" ) - # Mapping the class to their codes classMapping <- list( "1st-Year" = "c1", @@ -278,29 +414,22 @@ shinyServer(function(input, output) { "3rd-Year" = "c3", "4th-Year" = "c4" ) - yearCode <- yearMapping[[input$yearSelect]] classCode <- classMapping[[input$classSelect]] - # Generate the data for the tree map dat <- your_data_preparation_function(yearCode, classCode) # Assuming you have a function for this - # Call the inclusive_tree_fun function to generate the tree map tree_map <- inclusive_tree_fun(dat) - # Return the plotly object tree_map }) - - - -#### code if the computational cost of creating the maps is too much and we need to use already developed images +#### code if the computational cost of creating the maps is too much and we need to use already developed images # output$campusImage <- renderImage({ # # Ensure yearSelect and classSelect are not null # if (is.null(input$yearSelect) || is.null(input$classSelect) || input$yearSelect == "Overall") { # return("Select year breakdown :)") # } -# +# # # Mapping the years to their codes # yearMapping <- list( # "Spring 2018" = "ay1718", @@ -309,22 +438,22 @@ shinyServer(function(input, output) { # "Spring 2021" = "ay2021", # "Spring 2022" = "ay2122" # ) -# +# # # Mapping the class to their codes # classMapping <- list( -# "AllYears" = "c_all", # would require that those without class add "c_all" in png image name +# "AllYears" = "c_all", # would require that those without class add "c_all" in png image name # "1st-Year" = "c2122", # "2nd-Year" = "c2021", # "3rd-Year" = "c1920", # "4th-Year" = "c1819" # ) -# +# # yearCode <- yearMapping[[input$yearSelect]] # classCode <- classMapping[[input$classSelect]] -# +# # belongImage <- "" # dontBelongImage <- "" -# +# # # Constructing the image paths based on the typeSelect # if (input$typeSelect == "US Undergraduate") { # belongImage <- paste0("maps/map_cam_b_us_ug_", yearCode, "_", classCode, ".png") @@ -336,7 +465,7 @@ shinyServer(function(input, output) { # belongImage <- paste0("maps/map_cam_b_gr_", yearCode, "_", classCode, ".png") # dontBelongImage <- paste0("maps/map_cam_db_gr_", yearCode, "_", classCode, ".png") # } -# +# # # Rendering both images # tags$div( # tags$img(src = belongImage, style = "display:inline-block;margin-right:10px;"), @@ -344,10 +473,9 @@ shinyServer(function(input, output) { # ) # }) # } - - -######## campus bar plots ######## - ## good ## +###################### +## CAMPUS BAR PLOTS ## +###################### output$campusBarPlots <- renderReactable({ if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Overall") { reactable_fun(cam_us_ug) @@ -363,7 +491,7 @@ shinyServer(function(input, output) { inclusive_bar_fun(cam_us_ug_ay2122_c1819) #### spring 2020, 2021 was skipped } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "1st-through-5th-Year") { - inclusive_bar_fun(cam_us_ug_ay1920) + inclusive_bar_fun(cam_us_ug_ay1920) } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "4th-Year") { inclusive_bar_fun(us_ug_ay1920_1920) } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "3th-Year") { @@ -374,7 +502,7 @@ shinyServer(function(input, output) { inclusive_bar_fun(us_ug_ay2122_c1617) #### spring 2019 } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1st-through-4th-Year") { - inclusive_bar_fun(cam_us_ug_ay1819) + inclusive_bar_fun(cam_us_ug_ay1819) } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "4th-Year") { inclusive_bar_fun(us_ug_ay1819_1819) } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "3th-Year") { @@ -385,9 +513,9 @@ shinyServer(function(input, output) { inclusive_bar_fun(us_ug_ay1819_c1516) #### spring 2018 } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2018" && input$yearSelect == "1st-through-3th-Year") { - inclusive_bar_fun(cam_us_ug_ay1718) + inclusive_bar_fun(cam_us_ug_ay1718) } else if(input$typeSelect == "International" && input$intSelect == "Overall") { - inclusive_bar_fun(i) # where is this one?? + inclusive_bar_fun(i) # where is this one?? } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad Spring 2022") { inclusive_bar_fun(cam_i_ay2122) } else if(input$typeSelect == "International" && input$intSelect == "Undergrad Spring 2020") { @@ -396,7 +524,4 @@ shinyServer(function(input, output) { inclusive_bar_fun(cam_gr_ay2122) } }) - - ``` - From e6c3f00baa2c48d6f15d5c9a79cf712cde8f4b33 Mon Sep 17 00:00:00 2001 From: dfaragon Date: Wed, 26 Jun 2024 15:05:38 -0700 Subject: [PATCH 7/8] re-downloaded all files and updated campus-belonging with the correct version --- app/code/helper_code/campus-belonging.Rmd | 532 +++------------------- 1 file changed, 59 insertions(+), 473 deletions(-) diff --git a/app/code/helper_code/campus-belonging.Rmd b/app/code/helper_code/campus-belonging.Rmd index 3f92891..166f7c2 100644 --- a/app/code/helper_code/campus-belonging.Rmd +++ b/app/code/helper_code/campus-belonging.Rmd @@ -1,527 +1,113 @@ --- title: "Campus Belonging" --- + ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) -library(shinydashboard) -library(usethis) -use_git_config(user.name = "dfaragon", user.email = "dotz.da@gmail.com") ``` + ## What we need here: + - campus maps, broken into "belong" on top and "don't belong" on bottom - filter apply to both maps - maps are already extracted in "maps" folder: i have the standardized code for this already created so let me know if you are doing this piece -anwesha - hover for text (see NPS example) -- just heat maps? + ## Brian's Code ```{r} -library(reactable) -library(htmltools) -library(treemapify) -#function for interactive reactables -reactable_fun<- function(dat) { - options( - reactable.theme = reactableTheme( - color = "hsl(233, 9%, 87%)", - backgroundColor = "hsl(233, 9%, 19%)", - borderColor = "hsl(233, 9%, 22%)", - stripedColor = "hsl(233, 12%, 22%)", - highlightColor = "hsl(233, 12%, 24%)", - inputStyle = list(backgroundColor = "hsl(233, 9%, 25%)"), - selectStyle = list(backgroundColor = "hsl(233, 9%, 25%)"), - pageButtonHoverStyle = list(backgroundColor = "hsl(233, 9%, 25%)"), - pageButtonActiveStyle = list(backgroundColor = "hsl(233, 9%, 28%)") - ) - ) - rt<- dat %>% - reactable( - ., - groupBy = "agg_place", - showPageSizeOptions = T, - paginateSubRows = T, - defaultSorted = c("agg_place", "full_place"), - sortable = T, - showSortable = T, - striped = T, - highlight = T, - bordered = T, - defaultColDef = colDef( - vAlign = "center", - headerVAlign = "bottom" - ), - columns = list( - agg_place = colDef( - name = "Aggregated Place", - filterable = T, - align = "left", - minWidth = 240 - ), - full_place = colDef( - name = "Place", - align = "left", - minWidth = 215 - ), - n_b = colDef( - aggregate = "sum", - align = "center", - format = colFormat(separators = T, digits = 0), - html = T, - header = JS( - 'function(column) { - return `
n
` + "Belong" - }' - ) - ), - n_db = colDef( - aggregate = "sum", - align = "center", - format = colFormat(separators = T, digits = 0), - html = T, - header = JS( - 'function(column) { - return `
n
` + "Don\'t" + - "
Belong" - }' - ) - ), - perc_click_b = colDef( - aggregate = "sum", - align = "center", - format = colFormat(percent = T, digits = 1), - html = T, - header = JS( - 'function(column) { - return "Click" + "
Belong" - }' - ) - ), - perc_click_db = colDef( - aggregate = "sum", - align = "center", - format = colFormat(percent = T, digits = 1), - html = T, - header = JS( - 'function(column) { - return "Click" + "
Don\'t" + "
Belong" - }' - ) - ), - perc_stud_b = colDef( - aggregate = "sum", - align = "center", - format = colFormat(percent = T, digits = 1), - html = T, - header = JS( - 'function(column) { - return "Student" + "
Belong" - }' - ) - ), - perc_stud_db = colDef( - aggregate = "sum", - align = "center", - format = colFormat(percent = T, digits = 1), - html = T, - header = JS( - 'function(column) { - return "Student" + "
Don\'t" + "
Belong" - }' - ) - ), - incl = colDef( - aggregate = "mean", - name = "Inclusive", - align = "center", - format = colFormat(percent = T, digits = 1) - ) - ) - ) - return(rt) -} -#function for inclusiveness treemaps -inclusive_tree_fun<- function(dat) { - df<- dat - cp<- as.vector( - if_else(df$incl > 75, "#30313A", "#FCFFA4") - ) - plot<- dat %>% - ggplot( - ., - aes( - area = tot, - fill = incl, - label = place - ) - ) + - geom_treemap() + - geom_treemap_text( - place = "center", - grow = T, - reflow = T, - color = cp - ) + - scale_fill_viridis_c( - name = "Inclusiveness", - option = "inferno", - limits = c(0, 100) - ) + - theme( - panel.background = element_rect(fill = "#30313A"), - plot.background = element_rect(color = "#30313A", fill = "#30313A"), - legend.background = element_rect(fill = "#30313A"), - legend.title = element_text(color = "#FCFFA4"), - legend.text = element_text(color = "#FCFFA4"), - plot.margin = margin(0.5, 0.5, 0.5, 0.5, "cm") - #top, right, bottom, left, units - ) - return(plot) -} -#function for inclusiveness bar plots -inclusive_bar_fun<- function(dat, b_cp, e_cp) { - plot<- dat %>% - ggplot( - ., - aes( - x = agg_place, - y = incl, - fill = agg_place - ) - ) + - geom_bar( - stat = "identity", - position = "dodge" - ) + - xlab("") + - ylab("Inclusiveness") + - scale_y_continuous( - breaks = c(0, 25, 50, 75, 100), - limits = c(0, 125) - ) + - scale_fill_viridis_d( - option = "inferno", - begin = b_cp, - end = e_cp - ) + - coord_flip() + - geom_text( - aes(label = sprintf("%0.1f", incl)), - hjust = -0.5, - size = 5, - color = "#FCFFA4" - ) + - guides(fill = "none") + - theme( - panel.background = element_rect(fill = "#30313A"), - plot.background = element_rect(color = "#30313A", fill = "#30313A"), - panel.grid = element_blank(), - axis.title = element_text(size = 13, color = "#FCFFA4", hjust = 0.375), - axis.text = element_text(size = 12, color = "#FCFFA4"), - axis.ticks.y = element_blank() - ) - return(plot) -} + ``` -## Data Tables + +## Standardized ```{r} -# # bar plots -# tables_bp <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_bp.rds") -# # tree maps -# tables_tm <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_tm.rds") -# # reactable tables -# tables_rt <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_rt.rds") + ``` + + ## UI draft ```{r} dashboardBody( - tabItem(tabName = "table", + tabItem(tabName = "table", + # summary section - # includeMarkdown("www/summary.md"), + # includeMarkdown("www/summary.md"), fluidRow( column(3, uiOutput("dynamicFilter")), - column(3, reactableOutput("table")) %>% withSpinner(color = "navy")), - column(3, reactableOutput("table")) %>% withSpinner(color = "navy") #, + column(3, reactableOutput("table")) %>% withSpinner(color = "navy")) #add map tabItem )) ``` + + ## Server draft ```{r} # add reactable_fun() is here + shinyServer(function(input, output) { + # Dynamic UI for additional filters output$dynamicFilter <- renderUI({ - if(input$typeSelect == "US Undergraduate") { # added US for clarity - selectInput("yearSelect", "Select Year:", + if(input$typeSelect == "Undergraduate") { + selectInput("yearSelect", "Select Year:", choices = c("2018", "2019", "2020", "2022", "Overall")) } else if(input$typeSelect == "International") { - selectInput("intSelect", "Select Category:", + selectInput("intSelect", "Select Category:", choices = c("Overall", "Undergrad and Grad 2022", "Undergrad 2020")) + #add whichever remaining filter (see pbb HTML) } else { return() } }) -########################### -## CAMPUS SUMMARY TABLES ## -########################### + + + # Render the correct table based on the input selection output$table <- renderReactable({ if(input$typeSelect == "Undergraduate" && input$yearSelect == "Overall") { - reactable_fun(us_ug) + rt_cam_us_ug } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2022") { - reactable_fun(us_ug_ay2122) + rt_cam_us_ug_ay2122 } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2020") { - reactable_fun(us_ug_ay1920) + rt_cam_us_ug_ay1920 } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2019") { - reactable_fun(us_ug_ay1819) + rt_cam_us_ug_ay1819 } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2018") { - reactable_fun(us_ug_ay1718) + rt_cam_us_ug_ay1718 } else if(input$typeSelect == "International" && input$intSelect == "Overall") { - reactable_fun(i) + rt_cam_i } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad 2022") { - reactable_fun(i_ay2122) + rt_cam_i_ay2122 } else if(input$typeSelect == "International" && input$intSelect == "Undergrad 2020") { - reactable_fun(i_ug_ay1920) + rt_cam_i_ug_ay1920 } else if(input$typeSelect == "Graduate") { - reactable_fun(gr_ay2122) + rt_cam_gr_ay2122 } }) -###################### -## CAMPUS HEAT MAPS ## -###################### - output$campusHeatMaps <- renderImage({ - if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "AllYears") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay2122.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay2122.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "4th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay2122_c2122.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay2122_c2122.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "3th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay2122_c2021.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay2122_c2021.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "2th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay2122_c1920.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay2122_c1920.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "1th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay2122_c1819.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay2122_c1819.png", style = "display:inline-block;") - ) - #### spring 2020, 2021 was skipped - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "1st-through-5th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay1920.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay1920.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "4th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1920.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1920.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "3th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1819.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1819.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "2th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1718.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1718.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "1th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1617.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1617.png", style = "display:inline-block;") - ) - #### spring 2019 - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1st-through-4th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay2122_c2122.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay2122_c2122.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "4th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "3th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "2th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") - ) - #### spring 2018 - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2018" && input$yearSelect == "1st-through-3th-Year") { - tags$div( - tags$img(src = "maps/map_cam_b_us_ug_ay1718.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_us_ug_ay1718.png", style = "display:inline-block;") - ) - ### international - } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad Spring 2022") { - tags$div( - tags$img(src = "maps/map_cam_b_i_ay2122.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_i_ay2122.png", style = "display:inline-block;") - ) - } else if(input$typeSelect == "International" && input$intSelect == "Undergrad Spring 2020") { - tags$div( - tags$img(src = "maps/map_cam_db_i_ug_ay1920.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_i_ug_ay1920.png", style = "display:inline-block;") - ) - ### graduate student - } else if(input$typeSelect == "Graduate") { # no other option needed here - tags$div( - tags$img(src = "maps/map_cam_b_gr_ay2122.png", style = "display:inline-block;margin-right:10px;"), - tags$img(src = "maps/map_cam_db_gr_ay2122.png", style = "display:inline-block;") - ) - } - }) -}) -####################### -## CAMPUS TREE PLOTS ## -####################### -#### may be computationally expensive - output$campusTreeMaps <- renderPlotly({ - # Ensure yearSelect and classSelect are not null - if (is.null(input$yearSelect) || is.null(input$classSelect) || input$yearSelect == "Overall") { - return(NULL) - } - # Mapping the years to their codes - yearMapping <- list( - "Spring 2018" = "ay1718", - "Spring 2019" = "ay1819", - "Spring 2020" = "ay1920", - "Spring 2021" = "ay2021", - "Spring 2022" = "ay2122" - ) - # Mapping the class to their codes - classMapping <- list( - "1st-Year" = "c1", - "2nd-Year" = "c2", - "3rd-Year" = "c3", - "4th-Year" = "c4" - ) - yearCode <- yearMapping[[input$yearSelect]] - classCode <- classMapping[[input$classSelect]] - # Generate the data for the tree map - dat <- your_data_preparation_function(yearCode, classCode) # Assuming you have a function for this - # Call the inclusive_tree_fun function to generate the tree map - tree_map <- inclusive_tree_fun(dat) - # Return the plotly object - tree_map - }) -#### code if the computational cost of creating the maps is too much and we need to use already developed images -# output$campusImage <- renderImage({ -# # Ensure yearSelect and classSelect are not null -# if (is.null(input$yearSelect) || is.null(input$classSelect) || input$yearSelect == "Overall") { -# return("Select year breakdown :)") -# } -# -# # Mapping the years to their codes -# yearMapping <- list( -# "Spring 2018" = "ay1718", -# "Spring 2019" = "ay1819", -# "Spring 2020" = "ay1920", -# "Spring 2021" = "ay2021", -# "Spring 2022" = "ay2122" -# ) -# -# # Mapping the class to their codes -# classMapping <- list( -# "AllYears" = "c_all", # would require that those without class add "c_all" in png image name -# "1st-Year" = "c2122", -# "2nd-Year" = "c2021", -# "3rd-Year" = "c1920", -# "4th-Year" = "c1819" -# ) -# -# yearCode <- yearMapping[[input$yearSelect]] -# classCode <- classMapping[[input$classSelect]] -# -# belongImage <- "" -# dontBelongImage <- "" -# -# # Constructing the image paths based on the typeSelect -# if (input$typeSelect == "US Undergraduate") { -# belongImage <- paste0("maps/map_cam_b_us_ug_", yearCode, "_", classCode, ".png") -# dontBelongImage <- paste0("maps/map_cam_db_us_ug_", yearCode, "_", classCode, ".png") -# } else if (input$typeSelect == "International") { -# belongImage <- paste0("maps/map_cam_b_i_", yearCode, "_", classCode, ".png") -# dontBelongImage <- paste0("maps/map_cam_db_i_", yearCode, "_", classCode, ".png") -# } else if (input$typeSelect == "Graduate") { -# belongImage <- paste0("maps/map_cam_b_gr_", yearCode, "_", classCode, ".png") -# dontBelongImage <- paste0("maps/map_cam_db_gr_", yearCode, "_", classCode, ".png") -# } -# -# # Rendering both images -# tags$div( -# tags$img(src = belongImage, style = "display:inline-block;margin-right:10px;"), -# tags$img(src = dontBelongImage, style = "display:inline-block;") -# ) -# }) -# } -###################### -## CAMPUS BAR PLOTS ## -###################### - output$campusBarPlots <- renderReactable({ - if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Overall") { - reactable_fun(cam_us_ug) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "AllYears") { - inclusive_bar_fun(cam_us_ug_ay2122) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "4th-Year") { - inclusive_bar_fun(cam_us_ug_ay2122_c2122) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "3th-Year") { - inclusive_bar_fun(cam_us_ug_ay2122_c2021) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "2th-Year") { - inclusive_bar_fun(cam_us_ug_ay2122_c1920) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "1th-Year") { - inclusive_bar_fun(cam_us_ug_ay2122_c1819) - #### spring 2020, 2021 was skipped - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "1st-through-5th-Year") { - inclusive_bar_fun(cam_us_ug_ay1920) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "4th-Year") { - inclusive_bar_fun(us_ug_ay1920_1920) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "3th-Year") { - inclusive_bar_fun(us_ug_ay1920_c1819) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "2th-Year") { - inclusive_bar_fun(us_ug_ay1920_c1718) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "1th-Year") { - inclusive_bar_fun(us_ug_ay2122_c1617) - #### spring 2019 - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1st-through-4th-Year") { - inclusive_bar_fun(cam_us_ug_ay1819) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "4th-Year") { - inclusive_bar_fun(us_ug_ay1819_1819) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "3th-Year") { - inclusive_bar_fun(us_ug_ay1819_c1718) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "2th-Year") { - inclusive_bar_fun(us_ug_ay1819_c1617) - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1th-Year") { - inclusive_bar_fun(us_ug_ay1819_c1516) - #### spring 2018 - } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2018" && input$yearSelect == "1st-through-3th-Year") { - inclusive_bar_fun(cam_us_ug_ay1718) + + output$campusImage <- renderImage({ + # Decide which table to render after the data has been effectively filtered based on the following filters + if(input$typeSelect == "Undergraduate" && (is.null(input$yearSelect) || input$yearSelect == "Overall")) { + return("Select year breakdown :)") + } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2022") { + list(src = "maps/map_cam_b_us_ug_ay2122.png") + } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2020") { + list(src = "maps/map_cam_b_us_ug_ay1920.png") + } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2019") { + list(src = "maps/map_cam_b_us_ug_ay1819.png") + } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2018") { + list(src = "maps/map_cam_b_us_ug_ay1718.png") } else if(input$typeSelect == "International" && input$intSelect == "Overall") { - inclusive_bar_fun(i) # where is this one?? - } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad Spring 2022") { - inclusive_bar_fun(cam_i_ay2122) - } else if(input$typeSelect == "International" && input$intSelect == "Undergrad Spring 2020") { - inclusive_bar_fun(cam_i_ug_ay1920) - } else if(input$typeSelect == "Graduate") { # no other option needed here - inclusive_bar_fun(cam_gr_ay2122) + return("Select year breakdown :)") + } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad 2022") { + return(rt_cam_i_ay2122) + list(src = "maps/map_cam_b_i_ug_ay2122.png") + } else if(input$typeSelect == "International" && input$intSelect == "Undergrad 2020") { + return(rt_cam_i_ug_ay1920) + list(src = "maps/map_cam_b_i_ug_ay1920.png") + } else if(input$typeSelect == "Graduate") { + list(src = "maps/map_cam_b_gr_ay2122.png") } }) + +}) ``` + From 3027fd49c6774d8190aee77245167f2a9f49f928 Mon Sep 17 00:00:00 2001 From: Denicia Aragon Date: Thu, 27 Jun 2024 12:43:33 -0700 Subject: [PATCH 8/8] Update campus-belonging.Rmd --- app/code/helper_code/campus-belonging.Rmd | 349 ++++++++++++++++++++-- 1 file changed, 317 insertions(+), 32 deletions(-) diff --git a/app/code/helper_code/campus-belonging.Rmd b/app/code/helper_code/campus-belonging.Rmd index 166f7c2..4119f59 100644 --- a/app/code/helper_code/campus-belonging.Rmd +++ b/app/code/helper_code/campus-belonging.Rmd @@ -4,6 +4,9 @@ title: "Campus Belonging" ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) +library(shinydashboard) +library(usethis) +use_git_config(user.name = "dfaragon", user.email = "dotz.da@gmail.com") ``` ## What we need here: @@ -12,6 +15,7 @@ knitr::opts_chunk$set(echo = TRUE) - filter apply to both maps - maps are already extracted in "maps" folder: i have the standardized code for this already created so let me know if you are doing this piece -anwesha - hover for text (see NPS example) +- just heat maps? ## Brian's Code ```{r} @@ -23,6 +27,17 @@ knitr::opts_chunk$set(echo = TRUE) ``` +## Data Tables +```{r} +# # bar plots +# tables_bp <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_bp.rds") +# # tree maps +# tables_tm <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_tm.rds") +# # reactable tables +# tables_rt <- readRDS("/Users/daragon/Library/CloudStorage/OneDrive-UniversityOfOregon/OAR EXTERN/SWaSI/place-based belonging/pbb_tables_for_rt.rds") + +``` + ## UI draft ```{r} @@ -33,9 +48,15 @@ dashboardBody( # includeMarkdown("www/summary.md"), fluidRow( column(3, uiOutput("dynamicFilter")), +<<<<<<< HEAD + column(3, reactableOutput("table")) %>% withSpinner(color = "navy")))) + # column(3, inclusive_bar_fun("campusImage")) %>% withSpinner(color = +# )) +======= column(3, reactableOutput("table")) %>% withSpinner(color = "navy")) #add map tabItem )) +>>>>>>> main ``` @@ -47,13 +68,21 @@ shinyServer(function(input, output) { # Dynamic UI for additional filters output$dynamicFilter <- renderUI({ - if(input$typeSelect == "Undergraduate") { + if(input$typeSelect == "US Undergraduate") { # added US for clarity selectInput("yearSelect", "Select Year:", choices = c("2018", "2019", "2020", "2022", "Overall")) } else if(input$typeSelect == "International") { selectInput("intSelect", "Select Category:", choices = c("Overall", "Undergrad and Grad 2022", "Undergrad 2020")) +<<<<<<< HEAD +<<<<<<< HEAD + # Here, do I add an option for campus inclusiveness after choosing the hear and needing to choose all years, 4th-year, 3-rd year etc. +======= + #add whichever remaining filter (see pbb HTML) +>>>>>>> main +======= #add whichever remaining filter (see pbb HTML) +>>>>>>> main } else { return() } @@ -61,53 +90,309 @@ shinyServer(function(input, output) { # Render the correct table based on the input selection +######## campus summary tables ######## + ## do not change this is your original example and is correct ## output$table <- renderReactable({ if(input$typeSelect == "Undergraduate" && input$yearSelect == "Overall") { - rt_cam_us_ug + reactable_fun(us_ug) } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2022") { - rt_cam_us_ug_ay2122 + reactable_fun(us_ug_ay2122) } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2020") { - rt_cam_us_ug_ay1920 + reactable_fun(us_ug_ay1920) } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2019") { - rt_cam_us_ug_ay1819 + reactable_fun(us_ug_ay1819) } else if(input$typeSelect == "Undergraduate" && input$yearSelect == "2018") { - rt_cam_us_ug_ay1718 + reactable_fun(us_ug_ay1718) } else if(input$typeSelect == "International" && input$intSelect == "Overall") { - rt_cam_i + reactable_fun(i) } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad 2022") { - rt_cam_i_ay2122 + reactable_fun(i_ay2122) } else if(input$typeSelect == "International" && input$intSelect == "Undergrad 2020") { - rt_cam_i_ug_ay1920 + reactable_fun(i_ug_ay1920) } else if(input$typeSelect == "Graduate") { - rt_cam_gr_ay2122 + reactable_fun(gr_ay2122) + } + }) + + +######## campus heat maps ######## + output$campusHeatMaps <- renderImage({ + if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "AllYears") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "4th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122_c2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "3th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122_c2021.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122_c2021.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "2th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122_c1920.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122_c1920.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "1th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122_c1819.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122_c1819.png", style = "display:inline-block;") + ) + #### spring 2020, 2021 was skipped + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "1st-through-5th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1920.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1920.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "4th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1920.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1920.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "3th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1819.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1819.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "2th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1718.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1718.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "1th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1920_c1617.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1920_c1617.png", style = "display:inline-block;") + ) + #### spring 2019 + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1st-through-4th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay2122_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay2122_c2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "4th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "3th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "2th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1819_c2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1819_c2122.png", style = "display:inline-block;") + ) + #### spring 2018 + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2018" && input$yearSelect == "1st-through-3th-Year") { + tags$div( + tags$img(src = "maps/map_cam_b_us_ug_ay1718.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_us_ug_ay1718.png", style = "display:inline-block;") + ) + ### international + } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad Spring 2022") { + tags$div( + tags$img(src = "maps/map_cam_b_i_ay2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_i_ay2122.png", style = "display:inline-block;") + ) + } else if(input$typeSelect == "International" && input$intSelect == "Undergrad Spring 2020") { + tags$div( + tags$img(src = "maps/map_cam_db_i_ug_ay1920.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_i_ug_ay1920.png", style = "display:inline-block;") + ) + ### graduate student + } else if(input$typeSelect == "Graduate") { # no other option needed here + tags$div( + tags$img(src = "maps/map_cam_b_gr_ay2122.png", style = "display:inline-block;margin-right:10px;"), + tags$img(src = "maps/map_cam_db_gr_ay2122.png", style = "display:inline-block;") + ) } }) + +}) - output$campusImage <- renderImage({ + +# first version + # output$campusImage <- renderImage({ # Decide which table to render after the data has been effectively filtered based on the following filters - if(input$typeSelect == "Undergraduate" && (is.null(input$yearSelect) || input$yearSelect == "Overall")) { - return("Select year breakdown :)") - } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2022") { - list(src = "maps/map_cam_b_us_ug_ay2122.png") - } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2020") { - list(src = "maps/map_cam_b_us_ug_ay1920.png") - } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2019") { - list(src = "maps/map_cam_b_us_ug_ay1819.png") - } else if(input$typeSelect == "Undergraduate" && length(input$yearSelect) && input$yearSelect == "2018") { - list(src = "maps/map_cam_b_us_ug_ay1718.png") + # if(input$typeSelect == "US Undergraduate" && (is.null(input$yearSelect) || input$yearSelect == "Overall")) { + # return("Select year breakdown :)") + # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2022") { + # list(src = "maps/b_map_cam_us_ug_ay2122.png") + # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2020") { + # list(src = "maps/b_map_cam_us_ug_ay1920.png") + # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2019") { + # list(src = "maps/b_map_cam_us_ug_ay1819.png") + # } else if(input$typeSelect == "US Undergraduate" && length(input$yearSelect) && input$yearSelect == "2018") { + # list(src = "maps/b_map_cam_us_ug_ay1718.png") + # } else if(input$typeSelect == "International" && input$intSelect == "Overall") { + # return("Select year breakdown :)") + # } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad 2022") { + # return(rt_cam_i_ay2122) + # list(src = "maps/b_map_cam_i_ug_ay2122.png") + # } else if(input$typeSelect == "International" && input$intSelect == "Undergrad 2020") { + # return(rt_cam_i_ug_ay1920) + # list(src = "maps/b_map_cam_i_ug_ay1920.png") + # } else if(input$typeSelect == "Graduate") { + # list(src = "maps/b_map_cam_gr_ay2122.png") + # } + # }) + + +######## campus belong tree plots ######## +#### may be computationally expensive + output$campusTreeMaps <- renderPlotly({ + # Ensure yearSelect and classSelect are not null + if (is.null(input$yearSelect) || is.null(input$classSelect) || input$yearSelect == "Overall") { + return(NULL) + } + + # Mapping the years to their codes + yearMapping <- list( + "Spring 2018" = "ay1718", + "Spring 2019" = "ay1819", + "Spring 2020" = "ay1920", + "Spring 2021" = "ay2021", + "Spring 2022" = "ay2122" + ) + + # Mapping the class to their codes + classMapping <- list( + "1st-Year" = "c1", + "2nd-Year" = "c2", + "3rd-Year" = "c3", + "4th-Year" = "c4" + ) + + yearCode <- yearMapping[[input$yearSelect]] + classCode <- classMapping[[input$classSelect]] + + # Generate the data for the tree map + dat <- your_data_preparation_function(yearCode, classCode) # Assuming you have a function for this + + # Call the inclusive_tree_fun function to generate the tree map + tree_map <- inclusive_tree_fun(dat) + + # Return the plotly object + tree_map + }) + + + +#### code if the computational cost of creating the maps is too much and we need to use already developed images +# output$campusImage <- renderImage({ +# # Ensure yearSelect and classSelect are not null +# if (is.null(input$yearSelect) || is.null(input$classSelect) || input$yearSelect == "Overall") { +# return("Select year breakdown :)") +# } +# +# # Mapping the years to their codes +# yearMapping <- list( +# "Spring 2018" = "ay1718", +# "Spring 2019" = "ay1819", +# "Spring 2020" = "ay1920", +# "Spring 2021" = "ay2021", +# "Spring 2022" = "ay2122" +# ) +# +# # Mapping the class to their codes +# classMapping <- list( +# "AllYears" = "c_all", # would require that those without class add "c_all" in png image name +# "1st-Year" = "c2122", +# "2nd-Year" = "c2021", +# "3rd-Year" = "c1920", +# "4th-Year" = "c1819" +# ) +# +# yearCode <- yearMapping[[input$yearSelect]] +# classCode <- classMapping[[input$classSelect]] +# +# belongImage <- "" +# dontBelongImage <- "" +# +# # Constructing the image paths based on the typeSelect +# if (input$typeSelect == "US Undergraduate") { +# belongImage <- paste0("maps/map_cam_b_us_ug_", yearCode, "_", classCode, ".png") +# dontBelongImage <- paste0("maps/map_cam_db_us_ug_", yearCode, "_", classCode, ".png") +# } else if (input$typeSelect == "International") { +# belongImage <- paste0("maps/map_cam_b_i_", yearCode, "_", classCode, ".png") +# dontBelongImage <- paste0("maps/map_cam_db_i_", yearCode, "_", classCode, ".png") +# } else if (input$typeSelect == "Graduate") { +# belongImage <- paste0("maps/map_cam_b_gr_", yearCode, "_", classCode, ".png") +# dontBelongImage <- paste0("maps/map_cam_db_gr_", yearCode, "_", classCode, ".png") +# } +# +# # Rendering both images +# tags$div( +# tags$img(src = belongImage, style = "display:inline-block;margin-right:10px;"), +# tags$img(src = dontBelongImage, style = "display:inline-block;") +# ) +# }) +# } + + +######## campus bar plots ######## + ## good ## + output$campusBarPlots <- renderReactable({ + if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Overall") { + reactable_fun(cam_us_ug) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "AllYears") { + inclusive_bar_fun(cam_us_ug_ay2122) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "4th-Year") { + inclusive_bar_fun(cam_us_ug_ay2122_c2122) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "3th-Year") { + inclusive_bar_fun(cam_us_ug_ay2122_c2021) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "2th-Year") { + inclusive_bar_fun(cam_us_ug_ay2122_c1920) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "1th-Year") { + inclusive_bar_fun(cam_us_ug_ay2122_c1819) + #### spring 2020, 2021 was skipped + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2020" && input$yearSelect == "1st-through-5th-Year") { + inclusive_bar_fun(cam_us_ug_ay1920) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "4th-Year") { + inclusive_bar_fun(us_ug_ay1920_1920) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "3th-Year") { + inclusive_bar_fun(us_ug_ay1920_c1819) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "2th-Year") { + inclusive_bar_fun(us_ug_ay1920_c1718) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2022" && input$yearSelect == "1th-Year") { + inclusive_bar_fun(us_ug_ay2122_c1617) + #### spring 2019 + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1st-through-4th-Year") { + inclusive_bar_fun(cam_us_ug_ay1819) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "4th-Year") { + inclusive_bar_fun(us_ug_ay1819_1819) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "3th-Year") { + inclusive_bar_fun(us_ug_ay1819_c1718) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "2th-Year") { + inclusive_bar_fun(us_ug_ay1819_c1617) + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2019" && input$yearSelect == "1th-Year") { + inclusive_bar_fun(us_ug_ay1819_c1516) + #### spring 2018 + } else if(input$typeSelect == "US Undergraduate" && input$yearSelect == "Spring2018" && input$yearSelect == "1st-through-3th-Year") { + inclusive_bar_fun(cam_us_ug_ay1718) } else if(input$typeSelect == "International" && input$intSelect == "Overall") { - return("Select year breakdown :)") - } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad 2022") { - return(rt_cam_i_ay2122) - list(src = "maps/map_cam_b_i_ug_ay2122.png") - } else if(input$typeSelect == "International" && input$intSelect == "Undergrad 2020") { - return(rt_cam_i_ug_ay1920) - list(src = "maps/map_cam_b_i_ug_ay1920.png") - } else if(input$typeSelect == "Graduate") { - list(src = "maps/map_cam_b_gr_ay2122.png") + inclusive_bar_fun(i) # where is this one?? + } else if(input$typeSelect == "International" && input$intSelect == "Undergrad and Grad Spring 2022") { + inclusive_bar_fun(cam_i_ay2122) + } else if(input$typeSelect == "International" && input$intSelect == "Undergrad Spring 2020") { + inclusive_bar_fun(cam_i_ug_ay1920) + } else if(input$typeSelect == "Graduate") { # no other option needed here + inclusive_bar_fun(cam_gr_ay2122) } }) - -}) + + ```