cboettig commited on
Commit
0dde66d
·
1 Parent(s): 92a8f8c
Files changed (1) hide show
  1. app.R +7 -5
app.R CHANGED
@@ -25,7 +25,7 @@ ui <- page_sidebar(
25
  layout_columns(
26
  textInput("chat",
27
  label = NULL,
28
- "Which county has the highest average social vulnerability?",
29
  width = "100%"),
30
  div(
31
  actionButton("user_msg", "", icon = icon("paper-plane"),
@@ -70,7 +70,7 @@ ui <- page_sidebar(
70
  sidebar = sidebar(
71
 
72
  input_switch("redlines", "Redlined Areas", value = FALSE),
73
- input_switch("svi", "Social Vulnerability", value = FALSE),
74
  input_switch("richness", "Biodiversity Richness", value = FALSE),
75
  input_switch("rsr", "Biodiversity Range Size Rarity", value = FALSE),
76
  ),
@@ -118,7 +118,6 @@ chat <- ellmer::chat_vllm(
118
  )
119
 
120
  # helper utilities
121
- df <- tibble()
122
  # faster/more scalable to pass maplibre the ids to refilter pmtiles,
123
  # than to pass it the full geospatial/sf object
124
  filter_column <- function(full_data, filtered_data, id_col = "FIPS") {
@@ -132,6 +131,7 @@ filter_column <- function(full_data, filtered_data, id_col = "FIPS") {
132
 
133
  # Define the server
134
  server <- function(input, output, session) {
 
135
 
136
  observeEvent(input$user_msg, {
137
  stream <- chat$chat(input$chat)
@@ -152,6 +152,8 @@ server <- function(input, output, session) {
152
  output$table <- render_gt(df, height = 300)
153
 
154
  # We need to somehow trigger this df to update the map.
 
 
155
  })
156
 
157
  output$map <- renderMaplibre({
@@ -195,11 +197,11 @@ server <- function(input, output, session) {
195
  source = list(type = "vector",
196
  url = paste0("pmtiles://", "https://data.source.coop/cboettig/social-vulnerability/svi2020_us_tract.pmtiles")),
197
  source_layer = "SVI2000_US_tract",
198
- filter = filter_column(svi, df, "FIPS"),
199
  fill_opacity = 0.5,
200
  fill_color = interpolate(column = "RPL_THEMES",
201
  values = c(0, 1),
202
- stops = c("lightblue", "darkblue"),
203
  na_color = "lightgrey")
204
  )
205
  }
 
25
  layout_columns(
26
  textInput("chat",
27
  label = NULL,
28
+ "Which counties in California have the highest average social vulnerability?",
29
  width = "100%"),
30
  div(
31
  actionButton("user_msg", "", icon = icon("paper-plane"),
 
70
  sidebar = sidebar(
71
 
72
  input_switch("redlines", "Redlined Areas", value = FALSE),
73
+ input_switch("svi", "Social Vulnerability", value = TRUE),
74
  input_switch("richness", "Biodiversity Richness", value = FALSE),
75
  input_switch("rsr", "Biodiversity Range Size Rarity", value = FALSE),
76
  ),
 
118
  )
119
 
120
  # helper utilities
 
121
  # faster/more scalable to pass maplibre the ids to refilter pmtiles,
122
  # than to pass it the full geospatial/sf object
123
  filter_column <- function(full_data, filtered_data, id_col = "FIPS") {
 
131
 
132
  # Define the server
133
  server <- function(input, output, session) {
134
+ data <- reactiveValues(df = tibble())
135
 
136
  observeEvent(input$user_msg, {
137
  stream <- chat$chat(input$chat)
 
152
  output$table <- render_gt(df, height = 300)
153
 
154
  # We need to somehow trigger this df to update the map.
155
+ data$df <- df
156
+
157
  })
158
 
159
  output$map <- renderMaplibre({
 
197
  source = list(type = "vector",
198
  url = paste0("pmtiles://", "https://data.source.coop/cboettig/social-vulnerability/svi2020_us_tract.pmtiles")),
199
  source_layer = "SVI2000_US_tract",
200
+ filter = filter_column(svi, data$df, "FIPS"),
201
  fill_opacity = 0.5,
202
  fill_color = interpolate(column = "RPL_THEMES",
203
  values = c(0, 1),
204
+ stops = c("lightpink", "darkred"),
205
  na_color = "lightgrey")
206
  )
207
  }