cjerzak commited on
Commit
b196acf
·
verified ·
1 Parent(s): c0d7f46

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +42 -5
app.R CHANGED
@@ -341,12 +341,48 @@ server <- function(input, output, session) {
341
  )
342
 
343
  # Construct a label/popup-like text
 
 
 
 
 
 
344
  labels <- sprintf(
345
- "<strong>Country:</strong> %s<br/>
346
- <strong>%s Index:</strong> %s",
347
- plot_data$Country,
348
- index_col,
349
- ifelse(is.na(plot_data[[index_col]]), "N/A", plot_data[[index_col]])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  ) %>% lapply(htmltools::HTML)
351
 
352
  leafletProxy("cartogramPlot", data = plot_data) %>%
@@ -417,3 +453,4 @@ server <- function(input, output, session) {
417
  # Launch the Shiny App
418
  # =============================
419
  shinyApp(ui = ui, server = server)
 
 
341
  )
342
 
343
  # Construct a label/popup-like text
344
+ # Construct an indicator function for clarity
345
+ starIfSelected <- function(colName) {
346
+ if (index_col == colName) "*" else ""
347
+ }
348
+
349
+ # Build a label/popup to show all columns
350
  labels <- sprintf(
351
+ paste0(
352
+ "<strong>Country:</strong> %s<br/>",
353
+ "<strong>%sOverall:</strong> %s<br/>",
354
+ "<strong>%sRepresentation Gap:</strong> %s<br/>",
355
+ "<strong>%sEthnicity:</strong> %s<br/>",
356
+ "<strong>%sGender:</strong> %s<br/>",
357
+ "<strong>%sReligion:</strong> %s<br/>",
358
+ "<strong>%sLanguage:</strong> %s"
359
+ ),
360
+ # 1. Country
361
+ ifelse(is.na(plot_data$Country), "N/A", plot_data$Country),
362
+
363
+ # 2. Overall
364
+ starIfSelected("Overall"),
365
+ ifelse(is.na(plot_data$Overall), "N/A", plot_data$Overall),
366
+
367
+ # 3. RepresentationGap
368
+ starIfSelected("RepresentationGap"),
369
+ ifelse(is.na(plot_data$RepresentationGap), "N/A", plot_data$RepresentationGap),
370
+
371
+ # 4. Ethnicity
372
+ starIfSelected("Ethnicity"),
373
+ ifelse(is.na(plot_data$Ethnicity), "N/A", plot_data$Ethnicity),
374
+
375
+ # 5. Gender
376
+ starIfSelected("Gender"),
377
+ ifelse(is.na(plot_data$Gender), "N/A", plot_data$Gender),
378
+
379
+ # 6. Religion
380
+ starIfSelected("Religion"),
381
+ ifelse(is.na(plot_data$Religion), "N/A", plot_data$Religion),
382
+
383
+ # 7. Language
384
+ starIfSelected("Language"),
385
+ ifelse(is.na(plot_data$Language), "N/A", plot_data$Language)
386
  ) %>% lapply(htmltools::HTML)
387
 
388
  leafletProxy("cartogramPlot", data = plot_data) %>%
 
453
  # Launch the Shiny App
454
  # =============================
455
  shinyApp(ui = ui, server = server)
456
+